エラーが移行した後起こった:ここで私は分かりませんが、多分それはユニークな検証によってユニークスロー[42S22]:カラム見つかりません:1054不明列
を引き起こす
SQLSTATE[42S22]: Column not found: 1054 Unknown column 'id' in 'where clause' (SQL: select count(*) as aggregate from `phone` where `phone_number` = 0883991010 and `id` <>)
をリフレッシュすることは私ですコントローラ
if ($this->method() == 'PATCH') {
$name_rules = 'required|string|size:4|unique:student,name,' . $this->get('id');
$phone_rules = 'sometimes|numeric|digits_between:10,15|unique:phone,phone_number,' . $this->get('id') . ',id_student';
}
else {
$name_rules = 'required|string|size:4|unique:student,name,';
$phone_rules = 'sometimes|numeric|digits_between:10,15|unique:phone,phone_number,';
}
Phone.php
依頼<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class Phone extends Model
{
//
protected $table = 'phone';
protected $primaryKey = 'id_student';
protected $fillable = [
'id_student',
'phone_number',
];
public function student()
{
return $this->belongsTo('App\Student', 'id_student');
}
}
スキーマ
public function up()
{
Schema::create('phone', function (Blueprint $table)
{
$table->integer('id_student')->unsigned()->primary('id_student');
$table->string('phone_number')->unique();
$table->timestamps();
$table->foreign('id_student')->references('id')->on('tudent')->onDelete('cascade')->onUpdate('cascade');
});
}
それは私がユニーク取り除く際に正常に動作します:電話、PHONE_NUMBER、
任意のより良い提案?
を試してみていただきました!あなたは電話番号を格納するテーブルの名前は? –
テーブルのphone_number属性の列を確認します。 –
しかし、これらのコード行にはデータベースのアクティビティはありません。 – Amarnasan