Laravel: Delete migration before migrate:reset - php

I am new to Laravel. I am trying to reset all tables in my database using following command:
php artisan migrate:reset
Unfortunately I get this error:
Fatal error: Class 'AddAgeToPostsTables' not found in C:\xampp\htdocs\gitprojects\laravel
Before try to reset the tables I deleted a migration. Is there a way to solve this problem?

Since you're using Xamp, you should have access to PhpMyAdmin. Go find the database associated with your Laravel app, and then manually delete every table (but not the database itself). Then, run php artisan migrate. Since you deleted your migrations table, Laravel will re-run all of the up migrations. That should solve your error.

Try calling a composer dump-autoload.

Try to rollback the steps
php artisan migrate:rollback
And then migrate
php artisan migrate
Else manual delete the migration and tables from the db

check your drop() function in your migration file. Probably you left it blank.

delete the migration table from database.
then use
php artisan migrate:install
php artisan migrate

Related

Laravel Backpack - Eloquent trying to insert data in a wrong column name after database column rename

I'm facing a problem to save data by eloquent right after rename the database column name.
The column name was changed inside of the migration. The migration was carried out and the name in the database now is ok.
In the model, the column name was also changed to the new name.
But for some reason, when I try to insert a new record into the database, Laravel is complaining about the column name, it's trying to use the old name instead of the new name.
I'm currently using PHP 7 with Laravel 5.8 and Postgres as database. My environment is running on docker.
I already tried to clear the cache but it does not solved my issue.
Composer dump-autoload was also carried out but nothing changed.
This is the error:
Illuminate \ Database \ QueryException (42703)
SQLSTATE[42703]: Undefined column: 7 ERROR: column "name" does not exist LINE 1
Is import to say that i'm using Laravel Backpack.
It is possible due to cache issue sometimes so it is preferable to run following five commands after you do some changes to your migration or env file and Laravel isnt working as expected. Here is full explanation:
https://www.youtube.com/watch?v=Q1ynDMC8UGg
php artisan config:clear
php artisan cache:clear
composer dump-autoload
php artisan view:clear
php artisan route:clear
Please try these and see if it works after.
Please update your model and please also try with fluent query for testing like:
DB::table('users')->insert(array('name'=>'xyz'));

php artisan:rollback error in laravel 5.3

I tried building a database where I forgot to place the index of the table. Now I'm trying to rollback the migration but its not working out. It is throwing some error
[ErrorException] Undefined index: 2017_01_06_195028_create_users_themes_table
Now I tried deleting it manually so I deleted the migration file from the database folder and then did composer dump-autoload, and then did rollback it is still showing same error. Also when this didn't happened I tried placing index in the table through phpmyAdmin, it ain't helped! Still i deleted the table manually and tried doing composer dump-autoload and rollback it still has same error.
Help me out with this.
You can backup DB data (if any), drop DB and create it again and run php artisan migrate command. It's the easiest way to fix this I guess.
Another thing you could try is to delete last batch from migrations table and drop tables from last batch and run php artisan migrate
When you do php artisan migrate, migration table is created and it records the order of the migration you run. And when you rollback the list get cleared in the order of rollbacks..
In your case since you got an error the record corresponding to your migration probably still in the migration table.
Now if you wish to update your migration file and migrate again, you needs to manually clear the corresponding record from the migration table. Most probably it would be the last record in the migration table.
Clear out that record, fix your migration file and run your migration. You should be good to go.
I forgot to mention that I'm having my migration files in different folder so everytime I'm doing a php artisan migrate rollback I need to specify the path of those migration file that is why it is showing undefined Index error.

artisan migrate results: SQLSTATE[HY000]: General error: 1005 on LUMEN / LARAVEL

I'm trying to run php artisan migrate command but I am getting the following error.
I have looked at many forums and tried several solutions but nothing solved my problem.
What is going on?
-
Migrations:
http://pastebin.com/mDFa1suK
http://pastebin.com/tFWj9bEd
You can not create "produtos" table with a foreign key reference before creating "categorias" table
i suggest to change to change date in migration files name to re-order migration
so that migration of "categorias" table will run first
i hope that answered the question.
I notice that in your migration files, there are no table name cremasco.#sql-3076_1e but the error showing cannot create that table.
pls check your migration table in you database see if it has the cremasco.#sql-3076_1e. and run this in your command line :
composer dumpautoload then try again to migrate the database php artisan migrate
if the problem still exist then you need to drop your databases, and migrate again.
This problem exist because we deleted the files migration but the
table migration in database still has it
.

migrate command on laravel 5.1 console

I have created many tables use migration file, but I have dropped some table via the mysql command line tool, then I find the migration status about the tables I have dropped is still ran, so how can i fix it?
When I use migrate command, it always says nothing to migrate, but I have no table in my database.
I have tried to delete all the logs and stuff under the storage path.
I have also tried to delete the migration table on mysql or change .env file to use a new database, but both cannot work. Can anyone help me?
I use laravel 5.1.
`Run migrate:rollback (to undo the last migration)
If migrate:rollback doesn't work ; do it manually:
step 1 : delete the migration file
step 2 : composer dump-autoload (for resetting autoload file)
step 3 : remove the last entry from migration(to modify your database)`
The reason you are not able to migrate although you dont have existing tables in database is because your previous migrations still exist. Either clear the history or perform the above steps

Laravel 4 - Getting a fatal error when performing artisan:migrate

I've just started using Laravel and I'm having trouble with artisan and migrations.
I create a migration using: php artisan migrate:make create_clubs_table. I am able to then create a db schema.
But when I change the schema and create a new migration using the above command I get the following error:
PHP Fatal error: Cannot redeclare class CreateClubsTable in /var/www/clubb/app/database/migrations/2013_10_16_202121_create_clubs_table.php on line 43
Now, I know it's because I now have 2 migrations with the same class name, but isn't that the idea of migrations, or am I misunderstanding the docs? Am I supposed to delete the old migrations?
I think you've got it wrong. You shouldn't create a table twice with migrations. If you for some reason must (for example: you got one migration that drops the table after you've created it), then you can name it recreate_clubs_table or create_clubs_table_again.
If you only want to create it again and have no other migrations that alter that table after you've created it with the migration you can run it manually with php artisan tinker --env=local (env only needed if you're not in production). After you've executed the tinker command you can run (new CreateClubsTable)->down(); followed by (new CreateClubsTable)->up();. That will run your migration for the specific class.

Categories