我使用的是Laravel 5.2。我使用迁移方法创建了基本表。但现在我需要添加另一个额外的表。创建模式后,我给出了php artisan migrate
命令。但它显示的错误如base table or view already exists Table:Users
。我知道为什么会这样。迁移命令尝试重新创建已有的表。但是我需要通过Migration在Laravel中添加另一个额外的表。我已经完成了这个https://laravel.com/docs/5.2/migrations但我无法得到任何解决方案。
答案 0 :(得分:4)
如果您想创建另一个表,只需创建新的迁移并运行它。
如果您尝试将列添加到existsinng表中,请使用Schema::table
的{{1}}个实例。
Schema::create
答案 1 :(得分:1)
如果你已经执行了php artisan migrate
,那么下次它会给你错误说"表已经存在。"。
因此,如果您只想执行特定的迁移,则可以暂时从数据库/迁移文件夹中移动所有已执行的迁移php文件,然后执行
php artisan migrate
或
您可以从修补程序执行迁移,即首先执行php artisan tinker
,然后从迁移中执行向上方法的内容,但不包含参数类型蓝图。
EG。 如果以下是您的迁移方法内容
Schema::create('users', function (Blueprint $table) {
$table->increments('id');
$table->string('name');
$table->string('email')->unique();
$table->string('password', 60);
});
然后你必须执行
Schema::create('users', function ($table) {
$table->increments('id');
$table->string('name');
$table->string('email')->unique();
$table->string('password', 60);
});