我試圖在Laravel中創(chuàng)建外鍵,但是當(dāng)我使用I遷移表artisan時(shí),拋出以下錯(cuò)誤:[Illuminate\Database\QueryException]SQLSTATE[HY000]: General error: 1215 Cannot add foreign key constraint (SQL: alter table `priorities` add constraint priorities_user_id_foreign foreign key (`user_id`) references `users` (`id`)) 我的遷移代碼是這樣的:優(yōu)先級遷移文件public function up(){ // Schema::create('priorities', function($table) { $table->increments('id', true); $table->integer('user_id'); $table->foreign('user_id')->references('id')->on('users'); $table->string('priority_name'); $table->smallInteger('rank'); $table->text('class'); $table->timestamps('timecreated'); });}/** * Reverse the migrations. * * @return void */public function down(){ // Schema::drop('priorities');}用戶遷移文件public function up(){ // Schema::table('users', function($table) { $table->create(); $table->increments('id'); $table->string('email'); $table->string('first_name'); $table->string('password'); $table->string('email_code'); $table->string('time_created'); $table->string('ip'); $table->string('confirmed'); $table->string('user_role'); $table->string('salt'); $table->string('last_login'); $table->timestamps(); });}/** * Reverse the migrations. * * @return void */public function down(){ // Schemea::drop('users');}關(guān)于我做錯(cuò)了什么的任何想法,我想立即得到,因?yàn)槲倚枰獎?chuàng)建很多表,例如用戶,客戶,項(xiàng)目,任務(wù),狀態(tài),優(yōu)先級,類型,團(tuán)隊(duì)。理想我想創(chuàng)建與外鍵,i..e持此數(shù)據(jù)表clients_project和project_tasks等。希望有人可以幫助我入門。
- 3 回答
- 0 關(guān)注
- 655 瀏覽
添加回答
舉報(bào)
0/150
提交
取消