Laravel 5.1のマイグレーションを書きましたが、テーブル名とカラムの名前を変更した後、MySQLデータベースのマイグレーションを実行しますSQL Server 2008は列の名前を変更しようとして失敗し、次のエラーを出力します。Laravel 5.1のマイグレーションの列名を変更[SQL Server] [Linux]
Next Doctrine\DBAL\DBALException: An exception occurred while executing 'SELECT col.name,
type.name AS type,
col.max_length AS length,
~col.is_nullable AS notnull,
def.definition AS [default],
col.scale,
col.precision,
col.is_identity AS autoincrement,
col.collation_name AS collation,
CAST(prop.value AS NVARCHAR(MAX)) AS comment -- CAST avoids driver error for sql_variant type
FROM sys.columns AS col
JOIN sys.types AS type
ON col.user_type_id = type.user_type_id
JOIN sys.objects AS obj
ON col.object_id = obj.object_id
JOIN sys.schemas AS scm
ON obj.schema_id = scm.schema_id
LEFT JOIN sys.default_constraints def
ON col.default_object_id = def.object_id
AND col.object_id = def.parent_object_id
LEFT JOIN sys.extended_properties AS prop
ON obj.object_id = prop.major_id
AND col.column_id = prop.minor_id
AND prop.name = 'MS_Description'
WHERE obj.type = 'U'
AND (obj.name = 'roles' AND scm.name = SCHEMA_NAME())':
両方のデータベースでの移行が必要です。マイ移行コードは次のとおりです。
public function up()
{
Schema::create('cat_tipo_usuario', function (Blueprint $table) {
$table->increments('id_tipo_usuario');
$table->string('txt_tipo_usuario');
$table->timestamps();
});
//Se renombra la tabla
Schema::rename('cat_tipo_usuario','roles');
//Se cambia el nombre de las columnas
Schema::table('roles',function($tabla){
$tabla->renameColumn('id_tipo_usuario','id');
$tabla->renameColumn('txt_tipo_usuario','nombre');
});
}
私は、マイグレーションが正常に実行されますので、ドライバとの接続がうまく機能している列の名前を変更する行をコメントする場合。