I have a problem with Laravel (5.1.x) and Migrations. I am running it on an windows server with an integrated service account - so dont the application pool runs as the same account as the database.
Do get the correct scheme of my database, ill changed in the database.php file the name for the migrations table to:
'migrations' => 'dbo.migrations',
Because otherwise it will use my Scheme (because the command line runs as my account)
But when ill use that and run
php artisan migrate
It works only the first time, when i run it again, i tells me that there is already a migrations table in my database.
When ill use with:
'migrations' => 'migrations',
And the schema is now username.migrations it works when ill run the commands with my user.
It looks like that laravel is checking anywhere else if the migrations table exists, and try to create it again.
How can ill use the global database scheme with migrations (ill use that for every other tables too, and here it works fine as expected)
Any Ideas? Thanks in advance.
Related
Have been using Laravel for over a year now. My migrations folder has 39 files at the moment and i work (construct/destroy) with my database occasionally.
What happens is since ive created a "create_payments_table" migration, every migrate command that i execute builds all my tables normally but when login the migration history to my migrations table it stops at the 'create_payments_table' migration. So now when i create new migrations and run migrate again it tries to restart from my payments table which already exists giving me an error. Comparing my "create_payments_table" migration with the last logged migration file "create_pictures_table" it seems that everything is in order. Would like to know why my migrations create the tables but not all of them are been logged in migrations table?
My migrations table:
My migrations folder:
As u can see i added two new migrations and would like to run them without having to rollback my migrations table. But when doing so:
I get this error as artisan tryies to run de pauments migration again
You can migrate only a specific migration file :
php artisan migrate --path=/database/migrations/my_migration.php
Where my_migration will be your new migration file name like 2020_06_20_221554_create_additional_users_table
I am having a very bad situation here, working on a Laravel 5 project. previously developed by another developer. That developer at start created couple of tables using migration generators and added some columns using migrations. After that, he added table columns straight away using some sql GUI. I was given the sql dump which i imported and set it up on my local machine, now when i created a table using php artisan make:migration create_myTableName_table --create="myTableName" the table migration is created successfully, but, when i did php artisan migrate it's giving me SQLSTATE[42S01]: Base table or view already exists: 1050 Table 'someTable' already exists I checked migrations folder and matched it with current version of someTable and i can see the columns are different, same with other tables aswell.
What should be the best case to handle this in this situation, i want to keep up with Laravel migrations generator so that in future if any other developer want to work on this project he just has to run migration command to migrate database or to create tables or create columns... Should i re-write all migrations ? pleas help. Thanks
Given your situation, I’d put the .sql export in your repository, clear out the old, broken migrations, and create a new one that initially imports the database dump. Then just create migrations as normal going forward.
Quick and dirty?
Delete current migration files. Clear your migrations table and export the whole DB. Put the SQL dump in the repo and instruct other devs to import it before they run php artisan migrate. With the dump imported and migrations table truncated, you can create new migrations with no further collisions with the legacy migrations.
Feeling ambitious?
Use a package like migrations-generator to generate migrations based on your current DB structure. Then, migrate away.
Before I execute a migration on localhost I want to be sure that I can still execute the same migration on my server.
Will i still be able to execute the same migration remotely or will laravel mark that migration as done somewhere?
The migration information is stored inside the database that was migrated (in a "migrations" table). As long as your localhost and your server are not looking at the same database, you'll be fine.
I'm working on an app with multiple database connections. It seems when I run php artisan migrate:install it always creates the migrations table using my default connection in app/config/database.php, which is not ideal.
Is there a way to specify a different connection for the migrations table itself?
Update
For anyone with a similar question, I found a better answer.
Looks like you can't specify the connection from a config file or anything, but you can when you run migrate from the command line...
php artisan migrate:install --database=NAME_OF_CONNECTION
There is one caveat: anytime you run an actual migration you must also specify the database connection with --database again or it will re-create the migrations table using the default connection.
Edit: Looks like you want to change where the migrations table is stored. This I believe always uses the default. You can however specify where a table is supposed to be created as below:
You can specify a connection like so:
Schema::connection('foo')->create('users', function($table)
{
$table->increments('id');
});
From http://laravel.com/docs/schema
In Laravel 5.5 this worked for me:
php artisan migrate --database=sqlite_testing
I have a problem while working with SQLite database connection model in laravel 4.
After create schemas and run migrate:install, migrate, (db:seed) everything works perfectly. But if I delete the sqlite file for some reason, I am not able to recreate the file. migrate:install and migrate also run without any warnings but the app does not create the file. What am I doing wrong?
Laravel is not responsible for creating database files, they should exist when it tries to connect to them, but... PDO_SQLITE should create the database if it doesn't exists. Then, if it is not creating, you should check your folder permissions and webserver log files.