@kirill-93

Ошибка artisan migrate?

При установке внешних ключей не выполняется миграция, пишет "General error: 1005 Can't create table", при этом, если создать без внешнего ключа, а потом руками добавить его в базе, то все ок.
Миграции:
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();
        });

Собственно на последний внешний ключ (provider_id) и ругается. В чем может быть дело?
  • Вопрос задан
  • 159 просмотров
Пригласить эксперта
Ответы на вопрос 1
v_decadence
@v_decadence
У меня эта миграция развернулась нормально на тестовой базе.

Может дело в этом, что старые версии MySQL по умолчанию создают myISAM таблицы (они не поддерживают внешние ключи). Можно попробовать вручную задать движок перед операциями:

$table->engine = 'InnoDB';

Создание руками - это как именно? Может редактор сам переопределяет движок.

Подробнее
Ответ написан
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы