首先,我已經找到了這個錯誤,並沒有得到解決方案。我已經加入到我的用戶表的臨牀表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