Seeder already exists in Laravel - laravel

I migrated the table. Also, I created a seeder and using DB class to seed it. However, I am getting an error Seeder already exists. I used php artisan clear-compiled,
composer dump-autoload, php artisan optimize before running it. Please help me.

if i will run php artian make:seed TestSeeder and TestSeeder class or file already created in seeds/ folder then this error will occur Seeder already exists in Laravel.
Remove old file in seeds/ folder and make new seeder .

Related

Adding column using make migration command error

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.

no php artisan commands are working after new migration

I am new to laravel .
Following tutorial videos on laracast,i made a new migration (cmd command) like following
php artisan make:migration delete_title_from_posts_table
which gave me the message
Created Migration: 2020_02_05_185721_delete_title_from_posts_table
after that no php artisian command is working in cmd.
Any command i run gives me the following error
In Container.php line 805:
Target class [db] does not exist.
In Container.php line 803:
Class db does not exist
what would be causing this?
my laravel app version=6.2 and php version=7.3.5 on Win10 64-bit.
similar questions i already viewed,not working for me
artisan-commands-not-working-after-composer-update
in-container-php-line-805-target-class-db-does-not-exist
Since it's a facade, add this to the top of the class to make it work:
use DB;
Or use full namespace:
$tables = \DB::table...
run these commands steps by step:
composer dump-autoload clean up all compiled files and their paths
composer update --no-scripts Skips execution of scripts defined in composer.json
composer update update your project's dependencies

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.

Base table or view not found: 1146 Table 'db.ken_permissions' doesn't exist

Sometimes, when I type :
php artisan
php artisan migrate
etc
I get the message:
[Illuminate\Database\QueryException]
SQLSTATE[42S02]: Base table or view not found: 1146 Table 'db.ken_permissions' doesn't exist (SQL: select * from `ken_permissions`)
Debugging, I can tell my problem happens in the artisan file in:
$status = $kernel->handle(
$input = new Symfony\Component\Console\Input\ArgvInput,
new Symfony\Component\Console\Output\ConsoleOutput
);
I had already check this answer, and didn't work:
bootstrap/app.php is clean,
I don't have app/start folder ( L5.1),
routes.php is clean
php artisan -v or php artisan --pretend doesn't work, because artisan fails before running it seems.
The only thing I have is in app/Providers
public function boot(GateContract $gate)
{
parent::registerPolicies($gate);
// Dynamically register permissions with Laravel's Gate.
foreach ($this->getPermissions() as $permission) {
$gate->define($permission->name, function ($user) use ($permission) {
return $user->hasPermission($permission);
});
}
}
One solution is to delete all my tables, then composer dump-autoload, and then it work again, but it constantly comes back.
Is it a way to trace what migration is failing?
Any idea why is it happening?
Tx!
Go to the App\Provider\AuthServiceProvider
if you use on boot method GateContract ($this->getPermission() etc), remove or add to comment all after parent::registerPolicies($gate); and done run php artisan migrate
Adding to watcher's answer here
Remove any lines requesting data from your model from these files to be sure artisan is not trying to load data from your non-existent table:
bootstrap/start.php
app/start/global.php
app/start/local.php
app/routes.php
Also be sure to un-register any service providers that utilize data from that table in their register or boot methods inside of app/config/app.php.
You can move your migrations to a database/temp folder and run your migrations one by one
php artisan migrate --path=database/temp
you will know which migration is causing problem.
NOTE
Also you can use
php artisan migrate --pretend to get the query you are trying to do.

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