jeudi 29 septembre 2016

SQL error Many-to-Many migration file Laravel 5

I'm trying to create a new pivot table in my application. I want to connect my users table to my customers table. It must be a many-to-many relationship. I have created a migration file. It looks like this:

<?php

use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateUsersCustomersTable extends Migration
{
/**
 * Run the migrations.
 *
 * @return void
 */
public function up()
{
    Schema::create('customer_user', function (Blueprint $table) {
        $table->integer('user_id')->unsigned()->index();
        $table->foreign('user_id')
            ->references('id')
            ->on('users')
            ->onDelete('cascade');

        $table->string('customer_fb_id')->unsigned()->index();
        $table->foreign('customer_fb_id')
            ->references('facebook_id')
            ->on('customers')
            ->onDelete('cascade');

        $table->timestamps();
    });
}

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

When i run php artisan migrate i get the following error message:

[Illuminate\Database\QueryException]
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, `created_at` timestamp 
default 0 not null, `updated_at` times' at line 1 (SQL: create table `customer_user`
(`user_id` int unsigned not null, `customer_fb_id` varchar(255) unsigned not null, `created_at`
timestamp default 0 not null, `updated_at` timestamp default 0 not null)
default character set utf8 collate utf8_unicode_ci) 

In the users table the ID is an integer and in the customers table facebook_id is a string. In my opinion i'm doing it the right way, so I have no idea what i'm doing wrong?

Thanks in advance!



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2dgFzvR
via IFTTT

Aucun commentaire:

Enregistrer un commentaire