如何在 Laravel 中修改迁移?
问题描述
我正在尝试修改现有迁移.这是我当前的迁移课程:
我已经执行了一次 php artisan migrate 命令.现在我需要将 ->nullable() 方法添加到 error_message 列.所以我编辑了我的迁移,如下所示:
但是当我再次执行 php artisan migrate
时,它说:
没有要迁移的东西.
如何应用新版本的迁移?
你应该使用命令创建一个新的迁移:
然后,在创建的迁移类中,使用 change
方法添加这一行,如下所示:
要进行这些更改并运行迁移,请使用以下命令:
要回滚更改,请使用以下命令:
您可以通过向回滚命令提供 step
选项来回滚有限数量的迁移.例如,以下命令将回滚最近五次迁移:
<块引用>
详细了解使用迁移修改列
I'm trying to modify a existing migration. Here is my current migration class:
I've executed the php artisan migrate
command once. Now I need to add ->nullable()
method to the error_message
column. So I edited my migration, something like this:
But when I execute php artisan migrate
again, it says:
Nothing to migrate.
How can I apply the new version of the migration?
You should create a new migration using command:
Then, in that created migration class, add this line, using the change
method like this:
To make these changes and run the migration, use the command:
and to rollback the changes, use the command:
You may rollback a limited number of migrations by providing the step
option to the rollback command. For example, the following command will rollback the last five migrations:
See more about Modifying columns with Migration
这篇关于如何在 Laravel 中修改迁移?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!