【发布时间】:2015-07-24 16:35:06
【问题描述】:
我运行了一个名为 projects_table 的迁移
Schema::create('projects', function(Blueprint $table) {
$table->increments('id');
$table->string('name');
$table->integer('user_id');
});
我需要添加一个名为project_settings 的新列。我以为我可以添加
$table->text('project_settings');
然后运行php artisan migrate,但我错了,没用。然后我阅读了http://laravel.com/docs/5.0/schema#adding-columns 并了解到我必须使用Schema::table(...); 所以我将现有的迁移(projects_table)更改为:
Schema::table('projects', function(Blueprint $table) {
$table->increments('id');
$table->string('name');
$table->text('project_settings');
$table->integer('user_id');
});
这仍然不起作用。我终于通过创建一个新的迁移ProjectsTableNewField 并简单地添加了它来工作
Schema::table('projects', function(Blueprint $table) {
$table->text('project_settings');
});
我的问题是,这是在 laravel 中执行此操作的正确方法吗?添加列是一项非常基本的任务,如果我必须为每个数据库更改创建迁移,我认为迁移文件夹会很快变长。这样做的正确方法是什么?
编辑:我还看到有一个 created_at 和 updated_at 字段用于迁移目的很重要。我也会添加这些字段
【问题讨论】:
-
这个网站已经在制作中了吗?
-
不,不是。我目前正在使用 wamp。