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:
My migration with foreign keys:
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
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 !
Related
I'm using the PHP version of AlgoliaSearch with a laravel 5.2 installation.
I created a command I can run to reindex the data I have for one model. It works perfectly on some other but it seems that one has a problem.
When I try to run
\App\Models\User::reindex();
I get this exception :
AlgoliaSearch\AlgoliaException: cannot move with a master/slave index as source
I guess there is a problem with the way I configured my index and its slaves but I have no clue on that.
Does someone has more info please ?
I am just beginning to learn laravel and so I am constantly dealing with migration methods right now. Previously, I have deleted a migration file ShippedViaToPurchaseOrders and after that I cannot perform php artisan migrate:reset/rollback anymore. What is the problem with this? Please help. Please take a look with the error below. Thank you so much.
These files are loaded using composer, it still thinks the file is there.
Try running the composer dump-autoload command before running migrations to recreate the autoload file and let composer know the file is no longer there.
Update:
The Laravel migration tool creates a table migrations in your database to know what migrations have been executed. In this table, remove the row corresponding to the removed migration.
Because the row is still there, Laravel will keep trying to run the rollback migration corresponding to that row.
So basically I changed something in a migration in my laravel project and then tried running migrate:refresh and migrate:reset etc but was getting errors with files not found, so I dropped all of the tables in the phpmyadmin database and attempted to re-migrate.
So initially in the CMD it will say 'migration table created successfully' and then will do nothing else for a couple of minutes, after some time the xampp sql connection will close, giving an error 'Error: MySQL shutdown unexpectedly.'
So I restarted the sql server in xampp and checked the database and some of the migrations have run but not all of them, and the number it runs varies, sometimes it will make 7 of the tables, other times 15 but never does it create all of them successfully before the sql server shuts down.
I am working on a project in a team and this issue seems to be affecting only 2 out of 8 of us, for everyone else the migrations run perfectly after dropping all the tables and they have the exact same copy as me as we are using GIT.
I have tried:
Reinstalling xampp & composer,
re-making every single migration,
and re-cloning my repository from bitbucket.
I've asked around at work and no one seems to have seen this error/issue before so any help at all would be greatly appreciated.
Cheers,
Sam.
I have 38 migration script that I wrote in Laravel 4.
I don't want to throw them away, but I also don't want to run them either. I just want to keep them as references.
If I place them in the migration folder in Laravel, it will run when I do
php artisan migrate and that will break some part of my database, as they have already been run.
I'm wondering if there is a way to mark them as already run, so Laravel will not trying to run them again.
I notice the migration table in my database - can I do something with it ?
What is the best way I should do to those 38 migrations ? Feel free to give me any suggestions.
Your question is a little confusing -- Laravel will only run each migration once. It keeps track of which migrations have run in the migrations table. The whole idea of migrations is a series of date sortable scripts that you can run at anytime start to finish and they rebuild your database, AND that you can add to without needing to rerun them all as they work (so your data is preserved)
If you're running
php artisan migrate
and Laravel's running a migration it has already run, something is very broken with your system.
(Speculation follows) It seems more likely the latest migration you're running may have halted half way though in a place MySQL couldn't rollback the changes, and Laravel's trying to rerun the latest one. Try a
php artisan migrate:rollback
Fix the error in the breaking migration, and you'll be all set.
I'm trying to recover a project after a failed HDD. Lost the mysql information, so just have the project code.
I hoped to be able to put my database back together by using artisan migrate, but the error message tells me:
database.migrations doesn't exist
Is there actually a way I can use my Laravel code files and the command line to rebuilt my database like this?
Thanks for the help.
The command I needed to run was:
php artisan migrate:install
(I actually had more problems than this because the mysql install was messed up to. I don't know if simply php artisan migrate on its own would have implied :install but I'm adding it as an answer anyway should anyone have similar issues)