Migration Class CreateSessionTable error 301 - laravel-4

i accidentally execute php artisan migrate:session.
and it migrated, i delete the file createSessionTable,
and now i try to execute php artisan migrate:reset and the migrator in laravel still searching for CreateSessionTable.
i already use composer dump-autoload
composer dumpautoload
php artisan dump-autoload
php artisan dumpautoload
composer update // doesn't resolve the problem
it doesn't work anymore.
do you encounter it?

If you deleted the migration file you have two options:
1) Create a new one with the same name 2014_0000_create_session_table.php (the numbers doesn't really matter in this case, and rollback with it, you don't really need to create things in those methods (but you better create a drop method to drop that sessions table for you), you just need the class CreateSessionTable to be available for Laravel. After creating that file you'll need to composer dump.
2) Manually delete the line in the migrations table and also drop the sessions table.
You can also delete all your tables manually and all records on migrations file and then migrate again.

Related

Accidental deletion on Laravel Migration gives me migration not found

I accidentally deleted a migration file via my IDE manually earlier, after creating it and running php artisan migrate. now when im trying to run php artisan migrate:rollback, i get Migration not found: 2020_03_02_074557_add_dispute_into_company_order . How can i get my migration back?
If the rollback did not execute the task due to missing migration you may have a chance to recover your sql schema from database itself. From that part you can manually create a new migration.
Alternatively you can do as SKR suggested: try clicking 'undo' in your IDE.
You can try:
composer dump-autoload
It just regenerates the list of all classes that need to be included in the project

I can not migrate tables again

I deleted all tables in database, but my error is :
table.questions exists
so I can not migrate them, does it depend on something else as well?
You can run:
php artisan migrate:refresh
to rollback all the tables (including the migrations table) and recreate everything again.
It's impossible if you really removed all the tables from database.
Make sure you really deleted all tables including migrations table.
Normally when you want to revert all migrations you should run:
php artisan migrate:reset
If you haven't done this assuming you have are running Laravel 5.5 you can run:
php artisan migrate:fresh
I would advise you to read the whole Migrations documentation to know how they work and how you should create them. In fact you should not remove tables manually and just run:
php artisan migrate:rollback
to rollback migrations previously run or as I already said you can run one one previously mentioned commands to rollback or rollback and run again your migrations.
You get this error because you already have this table in DB. You need to drop a table in down() method of each migration and use php artisan migrate:rollback command to delete last batch of executed migrations.
In 5.5 you also can use php artisan migrate:fresh if you do not drop tables in the down() method.
https://laravel.com/docs/5.5/migrations#rolling-back-migrations
Or you can just manually recreate a DB and run php artisan migrate command.
I found it , I had a middleware in boot for question table and added this:
if(\Schema::hasTable('questions')) {
....
}

Laravel migration error when creating a new migration with same name that I deleted

Why do laravel has this error failed to open stream: no such file or directory.
I just deleted the 'makers' table and make a new one using php artisan make:migration command but now it has that error. Please help me
Make sure to run composer dump-autoload before running the migration.
In your terminal run:
composer dump-autoload
I think you forgot to delete migration from migrations table. For check run below given mysql query, If you found, remove it and try.
SELECT * FROM `migrations` WHERE migration = 'YOURMIGRATIONNAME';
This should work for you..!

Laravel migration undefined index

I am using Laravel 5.3.I deleted one of my migration files name 'feature' and everything related to it very carefully like its id from other tables etc.then i manually deleted the table from database.But now while i'm running the command "php artisan migrate:refresh".It's showing error exception with 'undefined index:***_create_features_table'.And when I'm running just 'php artisan migrate'.it shows that it was successful and all the tables successfully appear in the database.but then when i run migrate:refresh all the table disappears.what should i do to completely delete the migration file?
Try this.
First Manually delete the migration file under app/database/migrations/my_migration_file_name.php
Reset the composer autoload files: composer dump-autoload
Modify your database: Remove the last entry from the migrations table
Here is what I did.I cleared all the data from the database including all tables and then ran 'php artisan migrate'..that is how i made it work..But i am looking for a better solution which will not need to delete everything from the database.
Try check that you have the correct migrations first
php artisan migrate:status
Then you can try something like
php artisan migrate:refresh --step=1
And check again the status.
If you have Undefined index error and your migration was made with --path option, then add to your ModuleServiceProvier boot() method:
$this->loadMigrationsFrom(base_path('database/migrations/directory-name'));
in the migration just add $table->index(['column Name 1',''column Name 1']);
With my case, I forgot to do the Laravel migrate before running Infyomlabs to create scaffold!
So one of the reasons for "Undefined index" is that the table is not there yet.

php artisan migrate:reset failed to open stream: No such file or directory

when I ran
php artisan migrate:reset
I got
[ErrorException]
include(app/database/migrations/2014_08_06_120900_alter_xxx_table.php): failed to
open stream: No such file or directory
But I don't have that php file, I just have another file named
2014_08_06_121048_alter_xxx_table.php
And the migrations table in mysql has only
2014_08_06_121048_alter_xxx_table.php
but not
2014_08_06_120900_alter_xxx_table.php
Now I can't reset my database. What can I do about this?
First:
composer dump-autoload
Then make de rollback.
This work for me...
composer dump-autoload
php artisan migrate:rollback
php artisan dump-autoload
solve the same problem of mine.. rather than change manually
Deleting the row with 2014_08_06_121048_alter_xxx_table in table migrations didn't really solve the problem. When I run php artisan migrate:reset again, the problem comes again too.
Finally I find the essential reason myself. Due to some reason maybe some wrong commands, wrong filename had been written into
./vendor/composer/autoload_classmap.php
So I correct the filename in this file, everything works well now.
It sounds like you did a migration, then later on deleted a migration file before you did the rollback. So now Laravel is not sure how to rollback your database.
Easiest solution (since you are reseting anyway) is to manually clear all the tables from your database, including the migration table.
Then just run php artisan migrate and it will install the table and run your migrations.
In the future you should not manually alter your migration files unless you have rollbacked first.
Undo the actions the migration done on the database. Then look at the migrations table and remove the row relating to the file you deleted.
After that you might then need to run
composer dump-autoload
This command works
php artisan optimize
php artisan migrate:rollback
Look for the file autoload_classmap.php in /vendor/composer.
Open the file and edit the following:
In return array{ } remove the existing table.php files.
Example:
'CreatePasswordResetsTable' => $baseDir . '/database/migrations/2014_10_12_100000_create_password_resets_table.php',
'CreateUsersTable' => $baseDir . '/database/migrations/2014_10_12_000000_create_users_table.php',
I removed the above two lines from that array and again executed php artisan make:User -m and it created model as well as migration.
This same issue occurred to me while creating a sessions table. Basically it cannot find the path app/database/migrations/2014_08_06_120900_alter_xxx_table.php.
One possibility is that your database/migrations path is not app/database/migrations. So first you should find your correct path for database/migrations. I was using a october cms framework on top of it and found my path was "modules/system/database/migrations".
You need to open the SessionTableCommand.php in vendor/laravel/framework/src/Illuminate/Session/Console path. On the line #77 you will find $path variable. Change that to your path for database/migrations.
In my case line 77 looked like this:
$path = 'modules/system/database/migrations';
These errors happen mostly because of incorrect path for the file or directory.
php artisan dump-autoload
It do well in windows10.
Probably you should manually create folder migrations. Then composer update. And run migrations
Use this command. It worked for me.
php artisan migrate:rollback

Resources