주문 표가 있고 sell_shipping_labels
은 외국어로 orders.id
입니다.Laravel 마이그레이션 (errno : 150 "외래 키 제약 조건이 잘못 형성되었습니다.")
[Illuminate\Database\QueryException]
SQLSTATE[HY000]: General error: 1005 Can't create tablecheapbooks_test
.#sql-b5b_b2a
(errno: 150 "Foreign key constraint is incorrectly formed") (SQL: alter tablesell_shipping_labels
add constraintsell_shipping_labels_order_id_foreign
foreign key (order_id
) referencesorders
(id
))[Doctrine\DBAL\Driver\PDOException]
SQLSTATE[HY000]: General error: 1005 Can't create tablecheapbooks_test
.#sql-b5b_b2a
(errno: 150 "Foreign key constraint is incorrectly formed")
이 내 orders
테이블 스키마이다 : 나는 Laravel 마이그레이션을 실행하지만 때 나는 지칠대로 지친 오류 코드 얻을
Schema::create('orders', function (Blueprint $table) {
$table->increments('id');
$table->integer('user_id');
$table->integer('book_id');
$table->integer('status_id');
$table->double('payment_amount')->nullable();
$table->timestamp('received_at')->nullable();
$table->timestamp('paid_at')->nullable();
$table->timestamps();
$table->softDeletes();
});
을 그리고 이것은 내 sell_shipping_labels
스키마입니다 : 이제
Schema::create('sell_shipping_labels', function (Blueprint $table) {
$table->increments('id');
$table->unsignedInteger('order_id');
$table->string('shippo_object_id');
$table->string('label_url');
$table->string('tracking_url');
$table->string('tracking_number');
$table->timestamp('arrived_at');
$table->timestamps();
$table->softDeletes();
$table->foreign('order_id')->references('id')->on('orders');
});
}
나는 문제를 파악하려고 인터넷을 거꾸로 뒤집었다. 이 문제에 관한 모든 게시물은 모두 orders 테이블을 만들어야한다는 사실을 의미합니다. BEFORE 외래 키가있는 테이블이지만 내 파일의 순서가 맞지 않아서 문제가되지 않습니다. increments()
부호없는 정수 열을 생성하기 때문에
내 테이블 스키마하지만 여전히 동일한 오류 코드가 나타납니다. – FrenchMajesty
@FrenchMajesty DB를 다시 만들려고 했습니까? 그랬다면 구문이 정확한지 확신하기 때문에 새로운 오류 메시지를 게시하십시오. –
내 데이터베이스와 답안을 삭제하고 다시 만드는 것이 트릭입니다. 고맙습니다! – FrenchMajesty