安全删除Laravel中的迁移 [英] Safely remove migration In Laravel

查看:94
本文介绍了安全删除Laravel中的迁移的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Laravel中,似乎有一个用于创建迁移但不能删除的命令.

In Laravel, there appears to be a command for creating a migration, but not removing.

创建迁移命令:

php artisan migrate:make create_users_table

如果要删除迁移,是否可以安全地删除database/migrations文件夹中的相应迁移文件?

If I want to delete the migration, can I just safely delete the corresponding migrations file within the database/migrations folder?

迁移文件:

2013_05_31_220658_create_users_table

推荐答案

我不小心创建了一个名字错误的迁移文件(命令: php artisan migrate:make ).我没有运行( php artisan migrate )迁移,所以我决定将其删除. 我的步骤:

I accidentally created a migration with a bad name (command: php artisan migrate:make). I did not run (php artisan migrate) the migration, so I decided to remove it. My steps:

  1. 手动删除app/database/migrations/my_migration_file_name.php
  2. 下的迁移文件
  3. 重置作曲家的自动加载文件: composer dump-autoload
  4. 放松
  1. Manually delete the migration file under app/database/migrations/my_migration_file_name.php
  2. Reset the composer autoload files: composer dump-autoload
  3. Relax


如果您确实运行了迁移( php artisan migrate ),则可以执行以下操作:


If you did run the migration (php artisan migrate), you may do this:

a)-运行撤消上一次迁移的正确方法(Thnx @Jakobud)

a) Run migrate:rollback - it is the right way to undo the last migration (Thnx @Jakobud)

b)如果migrate:rollback不起作用,请手动执行(我记得以前版本中的migration:rollback的错误):

b) If migrate:rollback does not work, do it manually (I remember bugs with migrate:rollback in previous versions):

  1. 手动删除app/database/migrations/my_migration_file_name.php
  2. 下的迁移文件
  3. 重置作曲家的自动加载文件: composer dump-autoload
  4. 修改数据库:从 migrations 表中删除最后一个条目
  1. Manually delete the migration file under app/database/migrations/my_migration_file_name.php
  2. Reset the composer autoload files: composer dump-autoload
  3. Modify your database: Remove the last entry from the migrations table

这篇关于安全删除Laravel中的迁移的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆