How to configure an extra/different migrations folder
Update for Rails 5/6;
Rails 5 recommends setting additional migration paths in your config/database.yml
file. It's very easy, see this example;
development:
migrations_paths:
- "db/migrate/other_db"
- "db/migrate/something_else"
ActiveRecord::Migrator.migrations_path=
will be deprecated in Rails 6.
How to change the output folder for migrations with asp.net Core?
dotnet ef migrations add Initial --context EsportshubApi.Models.ApplicationDbContext -o YourFolderPath
dotnet ef migrations add
Adds a new migration.
Arguments:
Argument | Description |
---|---|
<NAME> | The name of the migration. |
Enable-migration change location of migration folder
If anyone is interested in how I actually managed to change the migrations folder via the package manager console, I added an extra line to the command:
enable-migrations -ContextProjectName DAL -ContextTypeName Context -ProjectName DAL
I found the solution by looking at the command references found here
How is the location of the migrations folder determined?
The migrations folder of the add migration commands is determined by the respective output directory argument of the command (--output-dir
or -o
for CLI dotnet ef migrations add
and -OutputDir
for PMC Add-Migration
). And as explained in the documentation of the both commands:
The directory use to output the files. Paths are relative to the target project directory. Defaults to "Migrations".
So you have to provide that parameter, for instance
Add-Migration SomeMigration -OutputDir Data\Migrations
Note that this would also change the migrations classes namespace.
Now, the cool thing not mentioned in the documentation is that you have to do that only once, because the next add migration commands actually default to the last migration folder.
With that being said, the best is to specify this for the very first migration you are adding.
In case you want to modify the existing project with already added migrations like shown in the question, then manually move the whole root "Migrations" folder to "Data", then optionally change the namespace of all .cs
files inside (including the .designer.cs
) to namespace {RootNamespace}.Data.Migrations
, and you are done. The next migrations will be added there without the need of specifying the folder.
How to specify folder for laravel migrations?
When creating new migrations and executing your migrations, you can pass in a path
parameter through the command line interface to specify the directory it will use to create and run the migrations respectively.
php artisan make:migration create_users_table --path=/path/to/your/migration/directory
php artisan migrate --path=/path/to/your/migration/directory
How do I enable EF migrations for multiple contexts to separate databases?
The 2nd call to Enable-Migrations is failing because the Configuration.cs file already exists. If you rename that class and file, you should be able to run that 2nd Enable-Migrations, which will create another Configuration.cs.
You will then need to specify which configuration you want to use when updating the databases.
Update-Database -ConfigurationTypeName MyRenamedConfiguration
How to add Extra properties to migration in .net core razor pages without deleting the previous migration or database in EF core
Updating with Code First Approach takes little extra care w.r.t Database First Approach.
Initially, you must enable migrations for the project
Enable-Migrations -ContextTypeName DBNAME.StoreContext
This will create a migration folder with the Configuration.cs file.
Next, we need to make our migration run. This is where you need to add an extra step to an existing database. If we create a migration now, it will attempt to add all our entities to the database. This will not work because other tables already exist in the database, so we need to create an initial blank migration and then later we will be able to add a migration for any new changes. To create blank migration execute this command
Add-Migration InitialCreate -IgnoreChanges
The key part of this command is the -IgnoreChanges flag, which ensures that migration is created that effectively does nothing. Running it will add an entry to the migrations table in the database, thus creating a snapshot of its original schema.
Next, run the update-database command to update the existing database with the initial migration. A new migrations table will now have been created in the DBNAME database.
Following this, you can add your properties, and after that execute this statementAdd-Migration add_classname_propertyname
After that run, the update-database
command and you are good to go.
Related Topics
Comparing Times Only, Without Dates
Unit Test in Rails - Model with Paperclip
Ruby: Get All Keys in a Hash (Including Sub Keys)
How to Introspect Things in Ruby
Can't Convert Fixnum to String During Rake Db:Create
How to Get a List of All Tags While Using the Gem 'Acts-As-Taggable-On' in Rails (Not the Counts)
Possible to Alias a Belongs_To Association in Rails
Best Way to Cache a Response in Sinatra
What's the Best Way to Parse a Tab-Delimited File in Ruby
How to Set a Blank Value for an F.Select Form Field
How Are Symbols Used to Identify Arguments in Ruby Methods
How to Uninstall Ruby on Rails and Do a Clean Install
Ruby on Rails: Provide VS Content_For
How to Delete All Contents of a Folder with Ruby-Rails