Skip to content
Advertisement

Laravel migrations won’t apply on MySQL (InnoDB)

Hello everyone,

This is my first time posting !

I am running into a problem when applying laravel 8 migrations on my new web server. While trying to deploy my projet I’m unable to apply migrations and I’m not sure why.

Below images of the error and my migration, i’m using the php artisan migrate --seed command

Outputed message when migrating: Outputed message when migrating

My migration with foreign keys: enter image description here

The problem seems to be associated with the foreign key constraints but it’s maybe because of something else. My server is running MySQL on InnoDB so I’m suspecting a compatibility problem, still, I have no clue how to solve it.

I tried:

  • Applying migrations one by one so that constraints would reference already existing foreign keys. Didn’t work
  • Changing my engine to InnoDB in config/database.php. Didn’t work
  • Importing my database manually using command line. Didn’t work
  • Adding DB_ENGINE = InnoDB to the .env file. Didn’t work
  • Switching from $table->foreign('idUser')->references('id')->on('users');
    to $table->foreignId('idUser')->nullable->constrained();

My server

  • Centos 7
  • MySQL – InnoDB
  • PHP 7.4
  • Has Cpanel

Also, I have no problem applying the migrations on localhost, whitch leads me to believe this is not a problem with the structure of the migrations…

I am running out of ideas and can’t seem to find a good awnser on the internet. Can someone help me ? Also please let me know if i forgot to provide important information

Advertisement

Answer

The problem was in fact with the way I wrote my migrations, if someone else has this problem, you can find a good awnser here: laravel-8-foreign-key

Thank you @brombeer for helping me !

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement