Closed loykianos closed 4 years ago
I just wanted to report this. It is becoming annoying having to fiddle with Telescope's database connection value in config/telescope
everytime I want to migrate my testing database.
Screenshot below
My solution was to create an .env.testing
with the entries:
APP_ENV=testing
APP_KEY=...
DB_CONNECTION=mysql_testing
TELESCOPE_ENABLED=0
CACHE_DRIVER=array
SESSION_DRIVER=array
QUEUE_DRIVER=sync
And then run:
art migrate:fresh --env=testing
that env
flag will load the .env.testing
file and will fix the issue with telescope migrations
@diogogomeswww nice work! I'm assuming that means you don't need to specify the --database=mysql_testing
option when running the command then?
@tim-mortimer ah yes, you are right, of course:
art migrate:fresh --env=testing
is enough.
(going to edit above)
I also have this issue. I also reached the point where the only solution that I have was to create an .env.testing file, but still, this shouldn't work like that, because it is confusing. Telescope should respect the --database parameter.
This is not an issue with Telescope, the migration is just a regular laravel migration and when you run migrate --database=x
you ask Laravel to run all the migrations on connection x.
Since you have telescope's migration using a specific connection, the migrator will try to run the migration on this connection and in which case the table already exists, hence the error.
I think both Laravel itself and telescope default their connections to the DB_CONNECTION
env variable so DB_CONNECTION=mysql_testing php artisan migrate
might work for some.
Just to add to the comment by themsaid above, since I got caught out by this and was confused as to what was occuring, Your default or, when using --database
, specified connection acts as the master record in regards to migrations. Telescope's migrations will use the telescope configured connection but that connection does not store a migration record itself, that's still in your "main" db connection.
Therefore when you attempt to use the --database
parameter Laravel will scan your specified connection for pending migrations. If the telescope migrations have not ran according to the migrations
table of the specified connection then they will be ran but using the connection defined in the telescope config.
Hence, if you have a testing database on a different connection and you try to migrate it, it may look in it's own migration
table and see that the telescope migration has not ran, try to run it but that specific migration will be ran against the telescope connection which still points to the other database.
Maybe a way to tell telescope to use the default database connection, instead of its own defined connection, would help?
Just stumbled upon this issue. It took me half an hour to figure out what was going on...
We don't have plans on changing this ourselves but feel free to attempt a PR if you like.
Came across this today and the easiest fix for myself ended up being:
TELESCOPE_ENABLED=0 php artisan migrate:fresh --database=testing
Hope this might help someone else if they get stuck.
I got around this issue by publishing the migrations...
php artisan vendor:publish --tag=telescope-migrations
Then in database/migrations/2018_08_08_100000_create_telescope_entries_table.php
adjusting the getConnection()
method.
public function getConnection()
{
return config('database.default');
//return config('telescope.storage.database.connection');
}
config('database.default')
at that point will return the database specified by your --database flag on the migration command: php artisan migrate --database=testing
Whenever I try using artisan migrate or migrate:refresh with the --database parameter (f.e. different testing database), telescope produces a "duplicate table" error.