Я устанавливаю строковый атрибут в качестве первичного ключа, и теперь я хочу установить связь между двумя таблицами. Я хочу объявить внешний ключ строки в другой таблице, чтобы убедиться, что эти две таблицы связаны. Но я получаю сообщение об ошибке, когда хочу перенести таблицы
Страна
Schema::create('countries', function (Blueprint $table) {
$table->string('country_name')->unique();
$table->primary('country_name');
$table->string('country_img');
$table->timestamps();
});
Направления
Schema::create('destinations', function (Blueprint $table) {
$table->increments('dest_id');
$table->string('dest_name');
$table->integer('dest_budget');
$table->double('dest_hrs');
$table->string('dest_country')->unsigned();
$table->foreign('dest_country')->references('country_name')->on('countries');
$table->string('dest_state');
$table->string('dest_address');
$table->string('lat');
$table->string('lng');
$table->string('dest_info');
$table->string('dest_ctgr');
$table->string('dest_img');
$table->timestamps();
});
Модель страны
protected $primaryKey = 'country_name';
public $incrementing = false;
protected $fillable = ['country_name', 'country_img'];
public function destinasi(){
return $this->hasMany(Destination::class);
}
Модель назначения
protected $primaryKey = 'dest_id';
protected $fillable = ['dest_name','dest_address','lat','lng','dest_ctgr','dest_budget','dest_hrs','dest_country','dest_state','dest_info','dest_img'];
public function country() {
return $this->belongsTo(Country::class);
}
Я получаю эту ошибку:
SQLSTATE [42000]: синтаксическая ошибка или нарушение доступа: 1064 У вас есть
ошибка в вашем синтаксисе SQL
Я думаю, что способ, которым я пишу внешний ключ, является неправильным и делает эту ошибку появившейся.