Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

[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');
    }
like image 308
Yosef Avatar asked Aug 29 '17 00:08

Yosef


Video Answer


1 Answers

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

Here:

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

The unsigned() method in Laravel description:

Set integer columns to UNSIGNED

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

like image 101
Wreigh Avatar answered Oct 13 '22 00:10

Wreigh