반응형
그래서 laravel에 대한 마이그레이션 파일에 외래 키를 설정하여 사용자 테이블이 간단하지만 스탠드 증분 대신 bigIncrements를 사용하려고합니다.
public function up()
{
Schema::create('users', function (Blueprint $table) {
$table->engine = 'InnoDB';
$table->bigIncrements('id')->unsigned();
$table->string('user_id')->unique();
$table->string('avatar');
$table->string('name');
$table->string('email')->unique();
$table->string('password')->nullable();
$table->rememberToken();
$table->timestampsTz();
});
}
그리고 다른 테이블을 수행 할 때 외래 키를 추가하려고하면 외래 키가 잘못 형성되었다는 오류가 발생합니다. 나는 열 유형을 일치시키기 때문에 어떻게 혼란스러워합니다. 여기 다른 테이블이 있습니다.
public function up()
{
Schema::create('social_logins', function (Blueprint $table) {
$table->engine = 'InnoDB';
$table->bigIncrements('id');
$table->bigInteger('user_id')->unsigned();
$table->foreign('user_id')->references('id')->on('users')->onDelete('cascade')->unsigned()->index();
$table->string('provider', 32);
$table->string('provider_id');
$table->string('token')->nullable();
$table->string('avatar')->nullable();
$table->timestamps();
});
}
해결 방법
다음에서 unsigned ()
제거 :
$table->bigIncrements('id')->unsigned();
그리고 다른 마이그레이션은 다음과 같아야합니다.
$table->bigInteger('user_id')->unsigned();
$table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
....
$table->index('user_id');
참조 페이지 https://stackoverflow.com/questions/42442498
반응형
'MySql' 카테고리의 다른 글
MySQL: Select rows with more than one occurrence (0) | 2020.10.28 |
---|---|
MySQL 명령 줄을 사용하여 SQL 쿼리를 TXT로 내보내는 방법 (0) | 2020.10.28 |
MySQL UPDATE에 타임 스탬프를 자동으로 삽입하도록 필드를 설정 하시겠습니까? (0) | 2020.10.28 |
MySQL 잘못된 날짜 시간 형식 : 1292 잘못된 날짜 시간 값 (0) | 2020.10.28 |
MySQL MYSQL : 테이블 "bar"에서 문자열 "foo"를 포함하는 모든 행 삭제 (0) | 2020.10.28 |
댓글