以下の初期移行して、データベース内のテーブルがあります:トラブル(コンポジット)キー
public function up()
{
Schema::create('products_markets', function (Blueprint $table) {
$table->increments('id');
$table->integer('product_id')->unsigned();
$table->foreign('product_id')->references('id')->on('products');
$table->integer('country_code_id')->unsigned();
$table->timestamp('created_at')->useCurrent();
$table->timestamp('updated_at')->useCurrent();
});
$sql = 'ALTER TABLE `products_markets` ADD UNIQUE `unique_index`(`product_id`, `country_code_id`)';
DB::connection()->getPdo()->exec($sql);
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('products_markets');
}
そして、すべてが正常に働いていました。 、
public function up()
{
Schema::table('products_markets', function (Blueprint $table) {
DB::unprepared("ALTER TABLE products_markets ADD INDEX country_code_id (country_code_id)");
DB::unprepared('ALTER TABLE products_markets MODIFY id INT NOT NULL');
DB::unprepared('ALTER TABLE products_markets DROP PRIMARY KEY');
DB::unprepared('ALTER TABLE products_markets DROP COLUMN id');
DB::unprepared('ALTER TABLE products_markets ADD PRIMARY KEY (country_code_id, product_id)');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('products_markets', function (Blueprint $table) {
DB::unprepared('DROP INDEX country_code_id ON products_markets');
DB::unprepared('ALTER TABLE products_markets DROP PRIMARY KEY');
$table->increments('id');
});
}
このコードは、ローカルでいくつかのマシン上で当社のサーバーと上で動作しますが:しかし、それは新しい移行が行われたid
自動インクリメントの主キーを持っている意味がありませんでしたということrealizedだったら
ProductTest :: test_scopeMarket_only_returns_products_for_user_country を照らし\データベース\のQueryException:SQLSTATE [42S22]:カラム見つかりません:他マシンがテスト中にエラーを投げているように見えます1054不明列 'ID' の 'where句'(SQL:
id
がnullproducts_markets
が= 121country_code_id
を設定、更新、updated_at
= 2016年8月29日夜05時05分21秒)
試験で次の行に質問のエラーがあります。
私たちは作者dumpautoload、再マイグレーション、キャッシュクリアを持っています。しかし、何も助けてくれないようです。これはDB::unprepared
〜ALTER
のテーブルを使用して行う必要がありますか?
idが新しいプライマリキー( 'product_id'、' country_code_id')に使用されているすべてのクエリを書き換える必要があります –
私はidがどんなクエリでも使われていないことを詳しく述べるべきだと思います。 –
テストコードのどこかで使用されているようです。 –