Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/59.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Illumb\Database\QueryException:SQLSTATE[42000]:语法错误或访问冲突:1064_Php_Mysql_Laravel - Fatal编程技术网

Php Illumb\Database\QueryException:SQLSTATE[42000]:语法错误或访问冲突:1064

Php Illumb\Database\QueryException:SQLSTATE[42000]:语法错误或访问冲突:1064,php,mysql,laravel,Php,Mysql,Laravel,我正在尝试将在laravel中创建的表迁移到数据库并使用外键。但是我得到了以下错误。请帮助我,错误在哪里 Illumb\Database\QueryException:SQLSTATE[42000]:语法错误或访问 违反:1064您的SQL语法有错误;请检查所需的手册 响应您的MariaDB服务器版本,以获取要在中使用的正确语法(接近“)” 第1行(SQL:alter tablepublicationsadd constraintpublications\u user\u id\u用于 外键(用

我正在尝试将在laravel中创建的表迁移到数据库并使用外键。但是我得到了以下错误。请帮助我,错误在哪里

Illumb\Database\QueryException:SQLSTATE[42000]:语法错误或访问 违反:1064您的SQL语法有错误;请检查所需的手册 响应您的MariaDB服务器版本,以获取要在中使用的正确语法(接近“)” 第1行(SQL:alter table
publications
add constraint
publications\u user\u id\u用于
外键(
用户id
)引用
注册
())

异常跟踪:

  • PDOException::(“SQLSTATE[42000]:语法错误或访问冲突:1064) 如果SQL语法有错误,请检查与Ma对应的手册 riaDB服务器版本,以便在第1行中使用接近“')”的正确语法) C:\xampp\htdocs\plearning\vendor\laravel\framework\src\illumb\Database \Connection.php:452

  • PDO::准备(“更改表格
    出版物
    添加约束
    出版物”\u用户
    _id_foreign
    外键(
    用户id
    )引用
    注册
    ()) C:\xampp\htdocs\plearning\vendor\laravel\framework\src\illumb\Database \Connection.php:452

  • 请使用参数-v查看更多详细信息

    父表为注册,其代码如下所示

     <?php
    
    use Illuminate\Support\Facades\Schema;
    use Illuminate\Database\Schema\Blueprint;
    use Illuminate\Database\Migrations\Migration;
    
    class CreateRegistrationsTable extends Migration
    {
        /**
         * Run the migrations.
         *
         * @return void
         */
        public function up()
        {
            Schema::create('registrations', function (Blueprint $table) {
                $table->increments('id'); //primary key
                $table->string('tname');
                $table->string('fname');
                $table->string('domicile');
                $table->integer('nic');
                $table->integer('phone');
                $table->string('email');
                $table->string('off_email');
                $table->string('password');
    
                $table->timestamps();
            });
        }
    
        /**
         * Reverse the migrations.
         *
         * @return void
         */
        public function down()
        {
            Schema::dropIfExists('registrations');
        }
    }
    
        <?php
    
    use Illuminate\Support\Facades\Schema;
    use Illuminate\Database\Schema\Blueprint;
    use Illuminate\Database\Migrations\Migration;
    
    class CreateEducationsTable extends Migration
    {
        /**
         * Run the migrations.
         *
         * @return void
         */
        public function up()
        {
            Schema::create('educations', function (Blueprint $table) {
                $table->increments('id');
                $table->integer('user_id')->unsigned();
                $table->foreign('user_id')->refrences('id')->on('registrations');
                $table->string('degree');
                $table->string('univ');
                $table->string('country');
                $table->integer('year');
                $table->text('research_area');
                $table->timestamps();
            });
        }
    
        /**
         * Reverse the migrations.
         *
         * @return void
         */
        public function down()
        {
            Schema::dropIfExists('educations');
        }
    }
    
        <?php
    
    use Illuminate\Support\Facades\Schema;
    use Illuminate\Database\Schema\Blueprint;
    use Illuminate\Database\Migrations\Migration;
    
    class CreatePublicationsTable extends Migration
    {
        /**
         * Run the migrations.
         *
         * @return void
         */
        public function up()
        {
            Schema::create('publications', function (Blueprint $table) {
                $table->increments('id');
                $table->integer('user_id')->unsigned();
                $table->foreign('user_id')->refrences('id')->on('registrations');
                $table->string('title');
                $table->string('status');
                $table->integer('year');
                $table->timestamps();
            });
        }
    
        /**
         * Reverse the migrations.
         *
         * @return void
         */
        public function down()
        {
            Schema::dropIfExists('publications');
        }
    }
    

    我发现您在迁移中拼写错误了
    references
    ,您能在所有迁移中将其更新为:

    …->引用(“…”)…


    如果这不能解决问题,则问题在于迁移的执行顺序,这意味着在运行迁移时文件顺序很重要

    同一问题,发布表已迁移,但其他两个未迁移。如果您检查迁移文件的顺序,您的顺序应如下所示:从上到下:
    注册,教育、出版物
    如何更改要更改文件的顺序,您需要重命名文件,只需重命名文件名中的日期,直到您获得正确的顺序。让我们来看看。
    $table->foreign('user_id')->references('id')->on('registrations')你的
    参考资料
    单词不正确