7

Consider

laravel new bug

Then adding in .env

DB_CONNECTION=sqlite
DB_DATABASE=/home/me/Code/bug/storage/database.sqlite

creating database

touch /home/me/Code/bug/storage/database.sqlite

migrating

php artisan migrate && php artisan migrate:fresh

Now trying to migrate programmatically in tinker

php artisan tinker
>> Artisan::call('migrate');

First time resulting in => 0 (as expected ?) But second time:

>>> Artisan::call('migrate:fresh')

Illuminate\Database\QueryException with message 'SQLSTATE[HY000]: General error: 17 database schema has changed (SQL: select * from sqlite_master where type = 'table' and name = migrations)'

Artisan::call('migrate') Third time:

Symfony\Component\Console\Exception\CommandNotFoundException with message 'There are no commands defined in the "migrate" namespace.'

Any ideas whats going on here? Can you reproduce?


Update using postgres. The second time running Artisan::call('migrate:fresh') I get:

Symfony\Component\Console\Exception\CommandNotFoundException with message 'There are no commands defined in the "migrate" namespace.'


UPDATE 2: Issue filed here: https://github.com/laravel/framework/issues/22997 https://github.com/laravel/tinker/issues/37

5
  • Confirming I can reproduce the error. FYI, you seem to have a typo in your database path. In .env you have it pointing to database, but when you create the file it's pointing instead to the database directory. Assuming this is a typo and not your actual steps, as I was able to reproduce while referencing the proper path. Commented Feb 1, 2018 at 18:58
  • Thanks! Yes that was a typo while drafting the post. Fixed in edit. Commented Feb 1, 2018 at 19:15
  • Have you tried getting it to work using MySQL yet? Worth a try to see if we can narrow it down to a sqlite driver issue or a larger Artisan issue Commented Feb 1, 2018 at 19:16
  • have you set 'ATTR_PERSISTENT' => TRUE in your connection config ? and APP_ENV=local ? Commented Feb 2, 2018 at 7:37
  • APP_ENV=local - yes, ATTR_PERSISTENT - no Commented Feb 2, 2018 at 7:53

1 Answer 1

3
+50

I don't think if this is a laravel bug, but I found your problem:

Calling a non existing command like Artisan::call('migrate:fresh') will crash. The reason is a typo: tinker does not accept fresh, only refresh. Calling the command via tinker will empty the sqllite file so you can't execute any commands until you migrate without tinker.

Here are my steps:

php artisan migrate # sqllite file is filled with content
php artisan tinker
> Artisan:call('refresh')
> Artisan::call('fresh') # now the sqllite file is empty
> Artisan::call('migrate') # will crash
php artisan migrate
> Artisan::('refresh') # works

so I think it's a tinker bug, not a laravel one. Tinker is doing some kind of snapshot (If you change a Model you have to restart tinker to call it there), maybe the error handling is not implemented is the best way to catch all errors.

Sign up to request clarification or add additional context in comments.

3 Comments

Thanks! Second paragraph, no? \Artisan::call('migrate:refresh') gives the exact same error as \Artisan::call('migrate:fresh'): There are no commands defined in the "migrate" namespace. But yes its tinker related as the commands are working in web.php (where I actually need them).
Refresh will not work if it crashed before. Only if you have a non empty sqllite file. You have to reset it with a non tinker call, then it should work
Thanks got it. Moved the issue to the correct repo: laravel/tinker

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.