W
W
WebDev2015-12-15 16:12:35
Laravel
WebDev, 2015-12-15 16:12:35

artisan migrate error?

When setting foreign keys, migration is not performed, writes "General error: 1005 Can't create table", while if you create it without a foreign key, and then manually add it to the database, then everything is ok.
Migrations:

Schema::create('users', function (Blueprint $table) {
            $table->increments('id');
            $table->string('name');
            $table->string('email')->unique();
            $table->string('password', 60);
            $table->rememberToken();
            $table->timestamps();
            $table->string('social_service');
            $table->integer('social_service_id')->unsigned();
            $table->enum('role', array('administrator', 'organizer', 'customer'));
        });

Schema::create('providers', function (Blueprint $table) {
            $table->increments('id');
            $table->string('name');
            $table->string('site');
            $table->timestamps();
        });

Schema::create('purchases', function (Blueprint $table) {
            $table->increments('id');
            $table->integer('user_id')->unsigned()->notNull();
            $table->string('name');
            $table->integer('provider_id')->unsigned()->notNull();
            $table->string('payment_method');
            $table->date('stop_date');
            $table->integer('min_amount')->unsigned();
            $table->integer('organizer_percent')->unsigned();
            $table->string('logo');
            $table->text('description');
            $table->boolean('show_in_web');
            $table->boolean('show_in_vk');
            $table->integer('status');

            $table->foreign('user_id')
                  ->references('id')
                  ->on('users')
                  ->onUpdate('cascade')
                  ->onDelete('cascade');

            $table->foreign('provider_id')
                  ->references('id')
                  ->on('providers')
                  ->onUpdate('cascade')
                  ->onDelete('cascade');

            $table->timestamps();
        });

Actually on the last foreign key (provider_id) also swears. What can be wrong?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Victor, 2015-12-15
@v_decadence

At me this migration was developed normally on test basis.
Maybe it's because older versions of MySQL create myISAM tables by default (they don't support foreign keys). You can try manually setting the engine before the operations:
$table->engine = 'InnoDB';
Creation by hand - how exactly? Maybe the editor itself redefines the engine.
More

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question