0
添加外鍵在laravel遷移文件我有以下代碼:無法在Laravel
Schema::table('stripe_customers', function (Blueprint $table) {
$table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
});
「USER_ID」是表「stripe_customers」現有的無符號整數列。
'id'是'users'中的主鍵列。
然而,當我運行遷移命令我收到以下錯誤信息:
[Illuminate\Database\QueryException]
SQLSTATE[HY000]: General error: 1005 Can't create table 'thedealerapp.#sql-47a_78859' (errno: 150) (SQL:
alter table `stripe_customers` add constraint stripe_customers_user_id_foreign foreign key (`user_id`)
references `users` (`id`))
[PDOException]
SQLSTATE[HY000]: General error: 1005 Can't create table 'thedealerapp.#sql-47a_78859' (errno: 150)
這究竟是爲什麼?
如果您刪除該調用並嘗試直接將其添加到數據庫,會發生什麼情況? – cwallenpoole
由於列類型或表格整理不匹配,通常會發生150錯誤。 – Robert
[MySQL外鍵錯誤1005 errno 150]的可能重複(http://stackoverflow.com/questions/4063141/mysql-foreign-key-error-1005-errno-150) – cwallenpoole