我試圖在Laravel中創建外鍵,但是當我使用I遷移表artisan時,拋出以下錯誤:[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`)) 我的遷移代碼是這樣的:優先級遷移文件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');}關于我做錯了什么的任何想法,我想立即得到,因為我需要創建很多表,例如用戶,客戶,項目,任務,狀態,優先級,類型,團隊。理想我想創建與外鍵,i..e持此數據表clients_project和project_tasks等。希望有人可以幫助我入門。
- 3 回答
- 0 關注
- 657 瀏覽
添加回答
舉報
0/150
提交
取消