Laravel에서 외래 키를 만들려고하는데 테이블을 마이그레이션 할 때 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등
누군가 나를 도울 수 있기를 바랍니다.
