[英]How sol solve this database migration issue?
我在Laravel数据库迁移方面遇到麻烦。 我在数据库迁移文件中输入了外键约束,但是当我尝试迁移文件时,它显示此错误消息。
Illuminate \\ Database \\ QueryException:SQLSTATE [42000]:语法错误或访问冲突:1064 SQL语法错误; 检查对应于您MariaDB的服务器版本,在1号线“上更新级联删除级联)”使用附近的正确语法手册(SQL:ALTER TABLE
education_qualifications
添加约束education_qualifications_teacher_id_foreign
外键(teacher_id
)引用teachers
()上删除级联在更新级联上):E:\\ XAMPP \\ htdocs \\ ViduresaApp \\ vendor \\ laravel \\ framework \\ src \\ Illuminate \\ Database \\ Connection.php:664
660| // If an exception occurs when attempting to run a query, we'll format the error
661| // message to include the bindings with SQL, which will make this exception a
662| // lot more helpful to the developer instead of just the database's errors.
663| catch (Exception $e) {
> 664| throw new QueryException(
665| $query, $this->prepareBindings($bindings), $e
666| );
667| }
668|
异常跟踪:
1 PDOException::(“ SQLSTATE [42000]:语法错误或访问冲突:1064您的SQL语法有错误;请在删除级联上检查与您的MariaDB服务器版本相对应的手册以在')附近使用正确的语法。更新级联'在第1行“)E:\\ XAMPP \\ htdocs \\ ViduresaApp \\ vendor \\ laravel \\ framework \\ src \\ Illuminate \\ Database \\ Connection.php:452
2 PDO :: prepare(“在更新级联上删除级联时,更改表
education_qualifications
添加约束education_qualifications_teacher_id_foreign
外键(teacher_id
)引用teachers
()”)E:\\ XAMPP \\ htdocs \\ ViduresaApp \\ vendor \\ laravel \\ framework \\ src \\ Illuminate \\ Database \\ Connection.php:452
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateEducationQualificationsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('education_qualifications', function (Blueprint $table) {
$table->increments('id');
$table->unsignedInteger('teacher_id')->nullable();
$table->unsignedInteger('student_id')->nullable();
$table->string('institute_name');
$table->string('user_degree');
$table->string('field_of_study');
$table->string('user_grade');
$table->date('from_date')->nullable();
$table->date('to_date')->nullable();
$table->text('edu_description');
$table->timestamps();
$table->foreign('teacher_id')->references('id')->on('teachers')->onUpdate('cascade')->onDelete('cascade');
$table->foreign('student_id')->references('id')->on('users')->onUpdate('cascade')->onDelete('cascade');
$table->primary(['teacher_id', 'student_id']);
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('education_qualifications');
}
}
您可以在同一行上同时使用onupdate和ondelete
例如:
$table->foreign(’author’)->references(’id’)->on(’users’)->onUpdate(’cascade’);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.