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.
Related
I'm using Laravel 5.8 and each time I create a new migration I run php artisan migrate:refresh to update my database. I lose data stored in tables that already exist. I want to find a solution to add a new table without losing my data.
You can run php artisan migrate (without :refresh), this only runs migrations that have not been run yet.
The idea with migrations is that you do not edit them after you run them.
More info on migrations can be found in the migration documentation
You can use the seeding too if you need some base data when you make a migration:refresh, please see the link to know more about that.
So, I've copied a database off a server that I'm working on and I've just started working on it. However for some reason the migrations table is empty so when I try to run php artisan migrate it can't because it doesn't know that all the tables are already created. Is there a quick way of fixing this rather then adding in the name of every migration to the table manually as there are a lot of migrations in this project?
Thanks.
You can work around it the following way:
Create another empty database.
Switch your application to use the new database.
Run php artisan migrate
Copy migrations table from new database to the old one
Switch your application to use the old database again.
You could also delete existing migration files (bad idea) or move them to some other folder so that migrate command doesn't see them.
You could also fill the table yourself, but that seems pretty time consuming.
Why is that table empty in the first place? Is it empty on your server as well?
So I just started playing around with Laravel 5.1. I created a model with migration named "teachers". Then I manually deleted the model file which was Teachers.php which contained the Teachers class. Now when I try to roll back I get the following error:
[Symfony\Component\Debug\Exception\FatalErrorException]
Class 'CreateTeachersTable' not found
I tried composer dump-autoload and php artisan migrate:refresh and php artisan migrate:reset but it keeps on giving above error. I just want to start afresh. How to reset everything?
Ok. So I found the solution. So if you accidentally delete any model file or migrations file without using php artisan migrate:rollback the above command and any migrate command will cause problems. SO what you need to do is, delete all the tables manually from the database. I was using sqlite database and I deleted migrations, users, questions, teachers, password_resets all the tables that were generated by migrate command. Then I ran composer dumpautoload. Then I ran php artisan migrate command again after making changes to the files and everything was back to normal.
So basically deleting migrations table solves the issue.
When you refresh your migrations, Laravel looks at your migrations table and uses the values in there to load the migrations files to rollback.
Since you manually deleted the migration file, it was never removed from your migrations table. You'll have to manually delete the row in that table for the given migration file.
First, check if that class is still referenced somewhere by doing a full search within your project folder, and then if it is not, try running:
php artisan clear-compiled
I need to install and configure an existing Laravel 4 project.
I tried to do, but when I ran composer update or composer install a lot of issues appear.
I have the database too (with data) so I ran the migration but doesn't work because the console show me an issue about the "table doesn't exist".
Can anyone tell me the complete process to configure the App?.
I mean, what its first, second and so and so because maybe in some step I made a mistake
To install and configure an existing project, you'd typically
Check out its source code
Run composer install
Run php artisan migrate
Check the README for specific instructions on installing 3rd party assets, or any additional steps you'd need to take
If the above creates errors, its either because of something in your environment (installing over an old project?) or some problem with the way the Laravel developer created their project.
To install and configure an existing project, you'd typically check those things first :
You should goto app/config/database.php check file and verify username and password.
After check in Project Folder vendor folder and composer.json file exist then remove it (that remove old configuration now we going to fresh configuration).
Then after back to command prompt and fire command composer update and that download some dependent file download.
Now Run php artisan serve
that tricks work for me last time when I migrate another host.
Carlos, when using an existing DB you'll need to check the migrations table to see which migrations have run successfully. Typically when taking over a laravel project setting up a new db and running the migrations against it is a good idea because you never know what hacks were made to the database outside the migration system. One small change can throw the entire system into a useless state because it's looking for a table or column that doesn't exist or has been modified. If you run the migrations against a bare db you can also figure out which tables were manually created (which could very well be your issue) outside the system and add them in as necessary. Cobbling things together after a previous developer is tedious, hopefully there is decent documentation.
Note that if you are using Git with .gitignore, don't forget to copy .env variables in new location too.
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.