【发布时间】:2019-05-07 18:05:02
【问题描述】:
我有两张桌子。一个是students_attendances,另一个是students。现在我想在这两个表之间设置一个外键。而且我还有字符串数据类型,我想在其上设置外键,但它给了我错误。下面是我的代码。回顾一下...
//students_attendances 表
public function up()
{
Schema::create('students_attendances', function (Blueprint $table) {
$table->increments('id');
$table->integer('class_id')->index()->unsigned()->nullable();
$table->string('student_id');
$table->string('first_name');
$table->string('last_name');
$table->string('attendance');
$table->timestamps();
$table->foreign('student_id')->references('student_id')->on('students')->onDelete('cascade');
});
}
//学生桌
public function up()
{
Schema::create('students', function (Blueprint $table) {
$table->increments('id');
$table->string('student_id');
$table->string('first_name');
$table->string('last_name');
$table->string('DOB');
$table->integer('students_class_id')->index()->unsigned()->nullable();
$table->string('gender');
$table->string('blood_group');
$table->string('religion');
$table->string('photo_id');
$table->string('student_address');
$table->integer('student_phone_no');
$table->string('guardian_name');
$table->string('guardian_gender');
$table->string('guardian_relation');
$table->string('guardian_occupation');
$table->integer('guardian_phone_no');
$table->string('email')->unique();
$table->string('NIC_no');
$table->string('guardian_address');
// $table->string('document_id');
$table->string('username');
$table->string('password');
$table->timestamps();
});
}
【问题讨论】:
标签: laravel