php – 向迁移失败的数据库表添加新列 – 无需迁移
发布时间:2020-12-13 21:56:45 所属栏目:PHP教程 来源:网络整理
导读:我刚刚学会了如何使用迁移.我成功创建了一个包含此架构的表: /** * Run the migrations. * * @return void */public function up(){ Schema::create('units',function (Blueprint $table) { $table-increments('id'); $table-string('name'); $table-string
我刚刚学会了如何使用迁移.我成功创建了一个包含此架构的表:
/** * Run the migrations. * * @return void */ public function up() { Schema::create('units',function (Blueprint $table) { $table->increments('id'); $table->string('name'); $table->string('description'); $table->timestamps(); }); } 不幸的是我错过了列路径,所以我试图添加它.首先,我通过laravel documentation告知myselfe,了解如何添加新列. 从文档:
我的尝试: /** * Run the migrations. * * @return void */ public function up() { Schema::create('units',function (Blueprint $table) { $table->increments('id'); $table->string('name'); $table->string('description'); $table->timestamps(); }); Schema::table('units',function (Blueprint $table) { $table->string('path'); }); } 但是,在执行php artisan migrate之后,我无法迁移. 我究竟做错了什么? 解决方法
您需要首先回滚迁移,这会破坏包含所有数据的上次迁移表:
php artisan migrate:rollback 然后再次运行php artisan migrate命令.这是应用程序开发过程中的最佳选择. 如果你不想出于某种原因(应用程序是实时等),但只想添加一列,然后创建一个新的迁移并添加此代码: public function up() { Schema::table('units',function (Blueprint $table) { $table->string('path'); }); } 并运行以下命令: composer dumpauto php artisan migrate (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |