我有以下列:
public function up()
{
Schema::create('stnk', function(Blueprint $table)
{
$table->increments('id');
$table->string('no_reg', 50)->unique();
$table->string('no_bpkb', 50)->unique();
$table->string('nama_pemilik', 100);
$table->string('alamat');
$table->string('merk', 50);
$table->string('tipe', 50);
$table->string('jenis', 50);
$table->smallInteger('tahun_pembuatan');
$table->smallInteger('tahun_registrasi');
$table->smallInteger('isi_silinder');
$table->string('no_rangka', 50);
$table->string('no_mesin', 50);
$table->string('warna', 50);
$table->string('bahan_bakar', 50);
$table->string('warna_tnkb', 50);
$table->string('kode_lokasi', 50);
$table->date('berlaku_sampai');
$table->timestamps();
$table->index('created_at');
$table->index('updated_at');
});
}
我已经创建了一个用于 stnk 表的数据填充器(seeder)。
现在我想将 id
重命名为 id_stnk
。
我在 "composer" 中添加了 "doctrine/dbal" 并运行了 composer update
。
我创建了迁移 php artisan migration:make rename_column
。
然后我添加了一个新方法到 rename_column:
Schema::table('stnk', function(Blueprint $table)
{
$table->renameColumn('id', 'id_stnk');
});
接着我尝试运行命令php artisan migrate
,但是我得到了下面提到的错误:
[Ulluminate\Database\QueryException]
SQLSTATE[HY000]: General error: 1025 Error on rename of './my_database/#sql -447_33' to './my_database/stnk' (error: 150) (SQL: ALTER TABLE stnk CHANGE id id_stnk INT UNSIGENED AUTO_INCREMENT NOT NULL)
[PDOException]
SQLSTATE[HY000]: General error: 1025 Error on rename of './my_database/#sql -447_33' to './my_database/stnk' (error: 150)
make:migration
而不是migrate:make
。 - Jasondoctrine/dbal": "~2.3"
。如果没有这个软件包,您将会遇到一些非常晦涩的错误。有人在这里提出了一个bug https://github.com/laravel/framework/issues/3116,并在文档中以较不实用的方式提到了这一点 http://laravel.com/docs/5.0/schema#renaming-columns - Jason