Laravel - migrations doesn't work after manual removal of tables - php

I have created 2 migrations in order to create 2 tables in Laravel, but I manually deleted these tables from database. Now, when I want to re-create these tables with migration, none of the following artisan commands works:
artisan migrate, artisan migrate:install, artisan migrate:refresh, artisan migrate:reset
It will return error like "nothing to migrate" or "tables [name] already exists" etc. I think laravel is somewhere keeping record of created tables. But how can I fix it now?

At first Manually delete all the Tables of your database also the migrations table, make your current database empty and then migrate the database and now you can use any artisan command for migration

Related

laravel migrate revert when stuck half-way

I ran laravel migration for given path dir only in new database.
Only migrations file from database/dmf_migrations directory is run.
And then half-way I get this Base table already exists error.
Here's the last migration run with batch no. 127:
I want to delete this existing table and run migrate again.
After deleting the table, can I continue with php artisan migrate --path=database/dmf_migrations or do I need to reset or rollback?
If there is no data in the tables then you can just run
php artisan migrate:fresh --path=database/dmf_migrations
It will drop all tables and re-run all migrations.
If you database has other tables or data, please don't use this command.

Masters table not found in database

I have an issue with laravel.
I have created a database named billing and connection is working fine for all tables. Now I created a new table named as masters. When I'm using this table then it is showing error base table or view masters not found
How can I resolve this issue?
This is usual for beginners. I have a few hints:
You might want to manually check the database, outside of Laravel, to
be sure the table has not been add.
Sometimes, you might just have misspelt the table name.
Did you forget to run the migration? If so, you need to run the
migration to add the table to the database. You can simple use php
artisan migrate on the command line.
If all these don't resolve it, dump you autoload files with composer and rerun your migration. You can use composer dumpautoload and then php artisan migrate:refresh
To create a migration, use the make:migration Artisan command:
php artisan make:migration create_masters_table
The new migration will be placed in your database/migrations directory.
You can use Laravel schema builder to expressively create and modify tables.
To run all of your outstanding migrations, execute the migrate Artisan command: php artisan migrate

php artisan migrate saying "nothing to migrate"

I've just got my MySQL database setup. When I run php artisan migrate, it creates the migrations table (which is empty) and then says "nothing to migrate". I have 3 migration files. I've tried php artisan migrate:reset, php artisan migrate:refresh and php artisan config:cache, but it still says the same thing. I've tried making a new database but the same comes from that. The empty migrations table is the only table in the database. Please help me fix this, thanks!
If you are altering a table, make sure you delete the information from the migrate table in your DB. I solved a similar problem by deleting the information from the migrate table in my DB.

how to re-migrate a laravel migration after deleting the table

after I've manually deleted a table in mysql, I run the command:
php artisan migrate
and I get this:
Nothing to migrate.
it only works the first time, how to re-run the migration in laravel?
Laravel keeps a record of migrations that have been run. You need to go to the migrations table and delete the migration record. Laravel does this so that it knows which migrations have been run so that it doesn't run them again and so that in the case of a rollback, it knows the last batch of migrations which were done.
This may help https://laravel.com/docs/5.6/migrations
Try composer dump-autoload AND php artisan config:cache
if not working also Try php artisan migrate:refresh.
OR Also Delete Migration table in database.
You can simply do: php artisan migrate: fresh to re-migrate your migration and if you have seeder data then you simply do: php artisan migrate: fresh -- seed
If you delete a table by hand, will have to delete the record from "migration" table too. This way when artisan migrate checks if your migration are not in "migration" table will migrate the unregistered ones.
That is the expected behaviour if you manually delete a table, because the previous batch migration job has already been deployed (in migrations table).
IF you want to re-migrate all the database, you can simply do: php artisan migrate:refresh.
IF you want to make sure your database to be clean with your latest changes, you can drop your entire database tables and do php artisan migrate again. Also, you can try php artisan migrate --seed if you have any seeder.
The best thing you can do is drop the table from the database and then rename the migration last number and do
php artisan migrate
This doesn't recreate all the tables.

Deleted a model manually, php artisan migrate gives and error

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

Categories