우선,이 오류를 이미 찾고 솔루션을 제공하지 않았습니다. 내 사용자 테이블 임상 테이블의 clinic_id foranea 키에 추가 왔지만 나는 다음과 같은 errror 얻을 마이그레이션 할 때 :외래 키 오류, '기본 테이블 또는 뷰가 이미 존재합니다.'laravel5
[Illuminate\Database\QueryException]
SQLSTATE[42S01]: Base table or view already exists: 1050 Table 'users' already exists (SQL: create table `users` (`id` int unsigned not null auto_increment primary key, `name` varc
har(150) not null, `surnames` varchar(150) not null, `email` varchar(150) not null, `password` varchar(150) not null, `phone` int not null, `clinic_id` int not null, `remember_toke
n` varchar(100) null, `created_at` timestamp null, `updated_at` timestamp null) default character set utf8mb4 collate utf8mb4_unicode_ci)
[PDOException]
SQLSTATE[42S01]: Base table or view already exists: 1050 Table 'users' already exists
2014_10_12_000000_create_clinics_table.php :
public function up()
{
Schema::create('clinics', function (Blueprint $table) {
$table->increments('id');
$table->string('name');
$table->string('country');
$table->string('province');
$table->timestamps();
});
}
을 2014_10_12_000001_create_users_table.php :
public function up()
{
Schema::create('users', function (Blueprint $table) {
$table->increments('id');
$table->string('name');
$table->string('surnames');
$table->string('email')->unique();
$table->string('password');
$table->integer('phone');
$table->integer('clinic_id');
$table->foreign('clinic_id')->references('id')->on('clinics');
$table->rememberToken();
$table->timestamps();
});
}
이전 프로젝트 버전으로 돌아 왔는데 그 오류가 다시 발생하지 않았으므로 지금은 분명히 모든 것이 올바르지 만 여전히 테이블 사용자에게 외부 필드를 추가하지는 않습니다. :
public function up()
{
Schema::create('users', function (Blueprint $table) {
$table->increments('id');
$table->string('name');
$table->string('surnames');
$table->string('email')->unique();
$table->string('password');
$table->integer('clinic_id');
$table->foreign('clinic_id')->references('id')->on('clinics');
$table->rememberToken();
$table->timestamps();
});
}
등.
public function up()
{
Schema::create('users', function (Blueprint $table) {
$table->increments('id');
$table->string('name');
$table->string('surnames');
$table->string('email')->unique();
$table->string('password');
$table->rememberToken();
$table->timestamps();
});
Schema::table('users', function (Blueprint $table) {
$table->integer('clinic_id');
$table->foreign('clinic_id')->references('id')->on('clinics');
});
}
테이블을 삭제하고 다시 마이그레이션을 수행하여 동일한 오류가 발생합니다 ... – jlgf
사용자 테이블에 대해 여러 마이그레이션이 있습니까? – aynber
사용자에게 단 하나의 마이그레이션이 있습니다. 매우 희귀합니다. – jlgf