[英]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.