I've run migration for a laravel module by
php artisan module:migrate
Then I wanted a rollback, so I've tried
php artisan module:rollback
There was no such command so I tried
php artisan migrate:rollback
But Laravel doesn't see it:
[Symfony\Component\Debug\Exception\FatalThrowableError]
Class 'AddInteractionsToVisits' not found
Am I doing something wrong? Is there a way to rollback module migration?
Since you're using a package, you should check their docs.
php artisan module:migrate-rollback Module
Check here https://nwidart.com/laravel-modules/v1/advanced-tools/artisan-commands
And if you need to rollback specific migration from module you can do this.
php artisan migrate:rollback --path=Modules/YourModule/database/migrations/2020_05_15_xxxxxx_create_your_table.php
I have use this code here instead Module doc code since it's giving an error.
php artisan migrate:rollback --path=...
And remember, If you are using linux servers careful about case sensitivity. You have to add like /Database/Migrations with starting capital.
/Database/Migrations/2020_05_15_xxxxxx_create_your_table.php
Related
This problem is not new, but I’ve looked and tried all the proposed solutions in other threads with no success.
I’m working with Laravel 8 with Homestead, is a new installation on a Windows 10 machine, not an upgrade.
I’m trying to seed a file called HotelSeeder.php. When I run the command
php artisan db:seed
I get the next error:
My HotelSeeder class goes like this:
My DatabaseSeeder class goes like this:
Both classes are located in the directory database/seeders
Autoload in composer.json goes like this:
After I run vagrant up and vagrant ssh, the commands that I’m running are:
php composer auto-load
php artisan db:seed
And the error shows up.
I've tried also:
php artisan db:seed --class=HotelSeeder
php artisan migrate:fresh –seed
php artisan clear:cache
php artisan optimize
Nothing seems to work. I hope you can help me.
Try the command:
composer dump-autoload --optimize
then:
php artisan db:seed
Your seeder class is named Database\Seeders\HotelSeeder. In your DatabaseSeeder.php file you should remove the alias for HotelSeeder as that is saying you want to alias a class from the root namespace named HotelSeeder which is not your class. If you remove that alias then the reference to HotelSeeder will actually be your correct class, Database\Seeders\HotelSeeder because the current namespace of this file is Database\Seeders so all class references are to that namespace.
Remove: use HotelSeeder;
Just a PHP namespacing thing.
Whenever I run any PHP artisan command (even php artisan help), I get:
[InvalidArgumentException]
Attribute [gett] does not exist
I haven't messed with my artisan file. How do I solve this?
Fixed this. Turns out I accidentally used Route::gett instead of Route::get. Found it by doing a global search.
I use Laravel 5.2 and I created database tables by running
php artisan make:migration create_categories_table --create=categories
and
php artisan make:migration create_posts_table --create=posts
and then I run php artisan migrate, and tables are created in database. But after I made some changes in migration file "create_posts_table.php" and run
php artisan migrate:rollback
I got an error:
[Symfony\Component\Debug\Exception\FatalErrorException]
Class 'CreatePostsTable' not found
PHP Fatal error: Class 'CreatePostsTable' not found in E:\programfiles\xampp\htdocs\deneme\vendor\laravel\framework\src\Illuminate\Database\Migrations\Migrator.php on line 336
my create_posts_table.php is
I tried composer update, composer dump-autoload but that hasn't fixed the problem.
I was getting the same problem. May this helps somebody: run composer dump-autoload before running migrate:rollback.
Before you run a migration, you should run the following commands to make sure cache has been cleared:
php artisan clear-compiled
php artisan optimize
This will make sure your new migration class has been registered correctly.
I have changed my application by using command
php artisan app:name [app_name].
Then, when I try to perform other actions using following artisan commands,
php artisan down
php artisan up
php artisan config:cache
I got the following error:
PHP Fatal error: Class 'App\Providers\AppServiceProvider' not found
How can I solve it?
It is working after Clearing bootstrap/cache directory.
This is how its worked out for me in the case of a fresh install.
First, I cleared the files in boostrap\cache.
Then, in config\app.php, I added the below line in the providers,
\Laravel\Telescope\TelescopeServiceProvider::class,
Then I ran the below commands
php artisan telescope:install
php artisan migrate
And it was working after this.
I don't know for what reason the telescope provider didn't work which was added by Laravel itself. i.e App\Providers\TelescopeServiceProvider::class.
By the way my laravel version was 7.12.0.
In my case, some extension of the VSCode, added a use Illuminate\Support\Facades\App; at the beginning of the file /config/app.php.
I solved it by removing the line from the file and running composer install.
You might have deleted the folder called providers
App/providers.
I had a question like yours then I solved it by copying app/providers directory from another Laravel project to my project thus it worked
I had the same issue, I solved it by,
migrate migration file - vendor>laravel>telescope>database>- manually.
check app.php file, if App\Providers\TelescopeServiceProvider::class, exist or not, have to exist
Run in command shell>
npm run dev
I've run artisan migrate:reset.
I've deleted some of my migration files because I didn't need these tables anymore.
I ran composer dump-autoload followed by artisan dump-autoload
I ran artisan migrate and I keep getting this error:
PHP Fatal error: Class 'Foo' not found in /vagrant/LaravelBackend/vendor/laravel/framework/src/Illuminate/Database/Migrations/Migrator.php on line 297
I tried to:
Run again composer dump-autoload and artisan dump-autoload (also used artisan clear-compiled)
Remove the migration table and run artisan migrate:install
Remove the vendor and composer.lock file and run composer install
Search within my project with PHPStorm for class Foo. Didn't find anything.
I keep getting the same error. It's the first time I run this since I updated to 4.2 if that could be related. Anything else I should be looking for?
I had this problem too.
Must remember: class name must be in accordance with filename.
Simple file renaming helped me:)
For example: in file "2014_12_08_100923_create_items_tables.php" must be class with name "CreateItemsTables" with using CamelCase words.
I solved my problem by
Removing all migration
Running composer dump-autoload
Adding them back one by one and running php artisan migrate
Deleting those that caused Laravel to throw an error
Create new migrations to replace the deleted ones
I'm not sure why that worked but my guess is that I might have modified the class name of these problematic migrations in the past.
I also found that renaming the migration with its initial name (The one throwed with the fatal error) also works for some of them.
I ran into this aswell and the solution was different to all of the above. The reason it was failing was because the filename was still mentioned in the migrations table of the DB. Because there were no unique columns I couldn't remove it with PHPMyAdmin and had to tak the CLI route.
Login to your server as root.
Type the following:
mysql -p database_name
(it now prompts for your password. From here on out everything is preceded with mysql > which just means that you're in the Mysql environment.
select * from migrations;
Look for the migration file you removed and copy the name.
delete from migrations where migration = '2015_07_21_000119_create_some_table';
It should mention something about 1 row affected. Now verify that it's gone by typing the first command again:
select * from migrations;
If it's gone exit the Mysql environment by typing
exit;
Now try 'php artisan migrate:rollback' again and it should work like a charm :-)
The actual solution is to use the correct naming for your translations. You still may need to do a
composer dump-autoload
The migration files must be as follows
YYYY_MM_DD_000000_create_some_table.php
and the class name inside must be
class CreateSomeTable extends Migration{}
There is an easier way.
Recreate those delete migrations manually. artisan make:migration
run artisan migrate:reset to rollback
Delete those dummy migations files just created.
run artisan migrate:refresh
I know this is a bit past but there is a better way actually. Run the following in terminal and feel free yourself to remove any of them:
~$ php artisan clear-compiled;php artisan cache:clear;php artisan config:clear;php artisan debugbar:clear;php artisan view:clear;php artisan optimize
To do it a regular task create an executable file named artisan-clear:
#!/bin/bash
php artisan clear-compiled
php artisan cache:clear
php artisan config:clear
php artisan debugbar:clear
php artisan view:clear
php artisan optimize
For me, the solution was that my class name inside the migration somehow started with a lowercase letter. When I changed the class name to be all upper case, then ran a composer dump-autoload, it ended up working for me. This is using Laravel 5.1, for what it's worth.
I did like this:
1. Deleted row non exist migration from migrations table from database
2. And run the command php artisan migrate:refresh
This helped to solve my problem.
*all your data will deleted from database tables
version 5.1.3 same problem fix it me:
drop database all tables
php artisan migrate:status
output: No migrations found.
ok use it
php artisan migrate:install
php artisan migrate
output is:
Migrated: 2016_11_24_093015_dt_some_table
Migrated: 2016_12_05_141004_dt_some_table
Migrated: 2016_12_07_110518_dt_some_table
Migrated: 2016_12_08_141807_dt_some_table
Migrated: 2016_12_13_090832_dt_some_table
this problem is solved
I had the same problem. When I was hiting php artisan migrate:reset, I got Class 'CreateImagesTable' not found. And composer dump-autoload didn't help.
My solution was very easy:
php artisan make:migration create_images_table --create=images
composer dump-autoload
Then I got:
SQLSTATE[HY000]: General error: 1 no such table: images (SQL: drop table "images")
so in sqlite I typed:
CREATE TABLE `images` (
...> `id` INTEGER
...> );
And then php artisan migrate:reset
Now I'm happy again
If artisan doesn't work at all and keeps throwing you this message no matter the command you give, delete the config.php file from bootstrap/cache folder.
After that run again
php artisan config:cache