Adding column using make migration command error - laravel

I'm trying to add an icon_path column to an existing table called tbl_device
by using php artisan make:migration add_icon_path_to_tbl_device_table --table=tbl_device
and after running php artisan migrate, it gives me this error.
PHP Fatal error: Cannot declare class CreateFailedJobsTable, because the name is already in use in ...path\database\migrations\<date>_create_failed_jobs_table.php
Cannot declare class CreateFailedJobsTable, because the name is already in use
I've also tried manually adding the icon_path column to the create_tbl_device_table.php migration and after running php artisan migrate it says Nothing to migrate.
I think I followed all the instructions.. any idea where I went wrong?

Call artisan migrate command only for your specific migration using:
php artisan migrate --path=/database/migrations/my_migrations
And see if it works.

Related

Laravel create table using migration error

I want to create a tbl_teacher_students table using migration..
My command is php artisan make:migration create_tbl_teacher_students_table.
I also tried adding --create=tbl_teacher_students but both gives me this error:
PHP Fatal error: Cannot declare class CreateFailedJobsTable, because the name is already in use
Symfony\Component\ErrorHandler\Error\FatalError
Cannot declare class CreateFailedJobsTable, because the name is already in use
I can't find anything about CreateFailedJobsTable error relating to migration.
Additional, I also tried adding column to an existing table but it gave me the same error.
This is happening, because on your database/migrataions/ directory create_failed_jobs_table..... created twice. Delete one. Then run composer dump-autoload and try again. This will solve the problem

Laravel Tinker error with SQLite database

Starting from a fresh project:
laravel new new-project
cd new-project
touch storage/database/database.sqlite
Then at .env
DB_CONNECTION=sqlite
DB_DATABASE=storage/database/database.sqlite
DB_FOREIGN_KEYS=true
The migration succeed...
php artisan migrate
php artisan tinker
>>>App\User::all()
But when I try to get all users it returns the following error:
PHP Fatal error: Class 'App/User' not found in Psy Shell code on line 1
What I could be missing?
Recently I reinstalled Laravel...
And I didn't realized I was using version Laravel 8
the models are at /app/Models
So the right command would be:
>>>App\Models\User::all()
i think it has something to do with the namespace alias. Try without the App/
Users::all();

How to rollback mistyped migration in Laravel?

I have created a migration using the command
php artisan make:migration create_members_table.php --create=members
So it created a class name CreateMembersTable.php including .. Now I want to rollback it and to correct the class name.
php artisan migrate:rollback --step=1
and I see this error as expected:
[Symfony\Component\Debug\Exception\FatalThrowableError]
Parse error: syntax error, unexpected '.', expecting '{'
OR
In order Laravel not to notice if I delete the file manually, how to do it?
Just delete the file and create a new one. Rollbacks are used for database not the migration files itself.
Or you can rename the file and the class name and if you get errors running the migration then run composer dump-autoload.

making model and migration with a single command in laravel 5.2

I've tried this artisan command as I followed a tutorial
php artisan make:model Foo -m
but I get this error:
exception 'RuntimeException' with message 'The "-m" option does not exist.'
why It's not recognizing that?
If It's a wrong way to do It , what the right one?
In short, this is how you do it.
C:\xampp\htdocs\lms>php artisan make:model Test -m
Model created successfully.
Created Migration: 2016_08_29_160434_create_tests_table
It must work. If that does not, do.
C:\xampp\htdocs\lms>composer install.
and that should work.

Laravel migrations messed up

I meesed up my Laravel migrations and I get PHP Fatal error: Cannot redeclare Class when running
php artisan migrate --path="workbench/fefe/feeds2go/src/migrations"
I have been deleting the migration file and dropping manually the table and recreated with php artisan migrate:make but still the same.
How can I fix migratons?
You need to check all of your migration class files and check for duplicate class names.
"Cannot redeclare class" happens when the class name appears at least
2 times.
The easiest way to do it is to run either composer install or composer.phar dump-autoload. It will generate warning information for you to identify which class is duplicated. Then, simply remove the class that declared twice.
Here is the error I got after I ran php artisan migrate
[Symfony\Component\Debug\Exception\FatalErrorException]
Cannot redeclare class CreateKidTimeslotTable
Therefore, I use composer.phar dump-autoload to identify the error.
Warning: Ambiguous class resolution, "CreateKidTimeslotTable" was found in both "laravel/database/migrations/2016_05_23_024341_create_kid_timeslot_table.php" and "laravel/database/migrations/2016_08_24_022635_create_kid_time_slot_table.php", the first will be used.
Remove the duplicated table that you don't need anymore.
You need to delete that migration file manually from the migration directory of your project and also, delete it's entry from the migration table in the database or you can run the php artisan migrate:refresh but it will drop your all table data so also add the your step with php artisan migrate:refresh --step=n
This is a late answer, but probably this would solve your issue.
Go to app/storage/migrations.
Delete the migration file that causes the error (You can also delete everything stored there).
Done.

Resources