Schema::drop('users'); Schema::dropIfExists('users'); 重命名带外键的数据表 在重命名前,你需要检查外键的约束涉及到的数据表名需要在迁移文件中显式的提供,而不是让 Laravel 按照约定来设置一个名称。因为那样会让外键约束关联到旧的数据表上。
你可以传递字段的名称数组至 dropCloumn 方法来移除多个字段:Schema::table('users', function ($table) { $table->dropColumn(['votes', 'avatar', 'location']); });注意:在SQLite 数据库中移除字段前,你需要先增加 doctrine/dbal 依赖至你的 composer.json 文件,并在你的命令行中运行 composer update ...
Schema::drop('users');Schema::dropIfExists('users');使用外键重命名表在重命名表之前,应该确认表的所有外键约束在迁移文件中有一个显式的名称,而不是让 Laravel 去指定。否则,外键约束名称将引用旧表名。字段创建字段门面Schema 的table 方法可用于更新表。与 create 方法一样, table 方法接受两...
要删除一个列,使用schema构建器上的dropColumn方法: 1Schema::table('users',function($table) {2$table->dropColumn('votes');3}); 你可以传递列名数组到dropColumn方法从表中删除多个列: 1Schema::table('users',function($table) {2$table->dropColumn(['votes', 'avatar', 'location']);3}); 注:...
Schema::drop('users'); Schema::dropIfExists('users'); 1. 通过外键重命名表 在重命名表之前,需要验证该表包含的外键在迁移文件中有明确的名字,而不是Laravel基于惯例分配的名字。否则,外键约束名将会指向旧的数据表。 6、列 创建列 要更新一个已存在的表,使用Schema门面上的table方法,和create方法一样,tab...
Schema::drop('users');Schema::dropIfExists('users');5.3 创建列要更新一个已存在的表,使用 Schema 门面上的 table 方法,和 create 方法一样,table 方法接收两个参数:表名和获取用于添加列到表的 Blueprint 实例的闭包:Schema::table('users', function ($table) { $table->string('email'); });...
function up() { Schema::create('file_storage', function (Blueprint $table) { $table->bigIncrements('id'); $table->string('path'); $table->timestamps(); }); } /** * Reverse the migrations. * * @return void */ public function down() { Schema::dropIfExists('file_storag...
最后, Schema::dropIfExists()当然会丢弃表,如果它存在。 有了这个方法,我们在up()方法中添加两行: public function up() { Schema::create('articles', function (Blueprint $table) { $table->increments('id'); $table->string('title'); $table->text('body'); $table->timestamps(); }); }...
要删除数据表,可使用 drop 或dropIfExists 方法:1 2 3 Schema::drop('users'); Schema::dropIfExists('users');重命名带外键的数据表在重命名表之前,你应该验证表上的任何外键约束在迁移文件中都有明确的名称,而不是让 Laravel 按照约定来设置一个名称。否则,外键的约束名称将引用旧表名。
public function down() { Schema::dropIfExists('users'); } } 运行迁移 要运行应用中所有未执行的迁移,可以使用 Artisan 命令的migrate方法。 Migration php artisan migrate 回滚迁移 想要回滚最新的一次迁移”操作“,可以使用rollback命令,注意这将会回滚最后一批运行的迁移,可能包含多个迁移文件: Migration ...