这是迁移?我必须将字符串数据列更改为具有现有数据的整数数据列
public function up()
{
Schema::table('SYS_tenants' ,function (Blueprint $table){
$table->integer('tena_type')->unsigned()->nullable()->change();
$table->foreign('tena_type')->references('id')->on('account_types');
});
}
根据laravel文档,您可以创建一个新的迁移并按以下步骤进行:
Schema::table('SYS_tenants', function (Blueprint $table) {
$table->integer('tena_type')->unsigned()->nullable()->change();
});
在修改列之前,请确保添加
doctrine/dbal
依赖项到您的composer.json
文件。
composer require doctrine/dbal
您可以在设置新字段类型后在要更改类型的字段上使用change
方法。
public function up() {
Schema::table('SYS_tenants' ,function (Blueprint $table){
$table->string('tena_type')->change();
});
}
我以为创建表的迁移已经调用了您需要的所有要求,例如unique
,nullable
等。您可以调用change
方法,对您要执行的任何修改都没有限制,例如在该字段上添加其他mysql索引。
不要忘记在doctrine/dbal
文件中添加composer.json
看起来您所拥有的应该起作用:
Schema::table('SYS_tenants' ,function (Blueprint $table){
$table->integer('tena_type')->unsigned()->nullable()->change();
});
取决于您的数据库,您可能需要将值转换为新类型:(对于mysql:https://www.mysqltutorial.org/mysql-cast/)