Laravel - SQLSTATE[42000]:语法错误或访问冲突:1064 迁移

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/45928955/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 16:33:54  来源:igfitidea点击:

Laravel - SQLSTATE[42000]: Syntax error or access violation: 1064 on migration

phpmysqllaravellaravel-5laravel-5.3

提问by Yosef

I never had this error until now it happens when I run php artisan migrate
I'm using MySQL 5.6.34
I tried everything I could think of ): and still have no luck I have a similar table to this and worked fine but for some reason, this once does not work

我从来没有遇到过这个错误,直到现在我运行 php artisan migrate 时才会发生
我正在使用 MySQL 5.6.34
我尝试了我能想到的一切):但仍然没有运气我有一个与此类似的表并且工作正常,但对于某些人原因,这一次不起作用

[PDOException]
  SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax
  to use near 'unsigned not null, `address_1` varchar(191) unsigned not null, `address_2` varch' at line 1

Here is my migration file

这是我的迁移文件

public function up()
    {
        Schema::create('rmaRequests', function (Blueprint $table) {
           $table->increments('id');
           $table->integer('user_id')->unsigned();
           $table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
           $table->string('reference_number')->unique();
           $table->string('first_name');
           $table->string('last_name');
           $table->string('email');
           $table->string('phone');
           $table->string('fax');
           $table->string('company');
           $table->integer('marketplaceId')->unsigned();
           $table->string('order_number')->unsigned();
           $table->string('address_1');
           $table->string('address_2');
           $table->string('city');
           $table->string('state');
           $table->string('zip');
           $table->integer('returnTypeId')->unsigned();
           $table->string('sku');
           $table->string('qty');
           $table->string('productName');
           $table->text('comments');
           $table->integer('status_id')->unsigned();
           $table->string('replacement_tracking');
           $table->string('return_tracking');
           $table->string('rma_number');
           $table->string('refund_number');
           $table->timestamps();
        });
    }



/**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::drop('rmaRequests');
    }

回答by Wreigh

I think it's because you're using unsignedto a varchar?

我想这是因为你习惯unsignedvarchar?

Here:

这里:

$table->string('order_number')->unsigned();

The unsigned()method in Laravel description:

unsigned()Laravel 中的方法描述:

Set integercolumns to UNSIGNED

integer列设置为 UNSIGNED

For more info: https://laravel.com/docs/5.4/migrations#column-modifiers

更多信息:https: //laravel.com/docs/5.4/migrations#column-modifiers