How remove particular migration from migration folder in asp.net ef core - asp.net-core

I am using asp.net ef core and I have to remove specific migration from the migration folder. How can I do that?

If u wanna delete your last migration after applying it to database use
Remove-Migration -Force
Or if u want to delete any particular migration then use
Remove-Migration "YourMigrationName" -Force
This worked for me.
Note : Be carefull and sure while removing any particular migration cz it might affect your database.

If U Wanna Deleted Your Last Migration You Can Use
Remove-Migration
but if you get this error
**The migration Your Migration Name has already been applied to the database. **
this mean you use Update-Database and your migration add in database so if you wanna delete this migration you should find migration table in you Database and delete from migration table and delete any table you don't need that. and again use
Remove-Database and this will work.
If your data isn't big so you can use this but be careful maybe your data you had save
will delete ....

Related

How can I run a specific migration in Symfony 5 for my mysql database?

Hi every body I'm learning Symfony 5, on migrations lessons, after a lot of make:migration commands, this time I've this messageenter image description here
And on doctrine:migrations:migrate command, I've this error
enter image description here
But in my migrations file , there's a migration with create etudiant table.
So I'll know how to run that one migration for having that table in my database, Thanks!
This Error often happened when you got some differents between the last migration file and your BDD.
First of all your script seems to drop 'etudiant' table but this one does not exist. May be you have drop it before.
However you have many possibility :
You can delete all migration file on your symfony project (under migrations folder), then delete all sql entry on doctrine_migration_versions.
After that you can redo your migration command line (make:migration and doctrine:migrations:migrate).
You can edit the last migration file on your symfony projet and delete the drop table in trouble.

dotConnect Oracle - migrations - Initial migration in two identical branches says differing model

I have just started testing migrations in several different team scenarios to make sure migrations will work as expected with git / multiple users / multiple branches. But I have run into an issue right off the bat. On branch 1 I added my Initial migration (on an existing project with 165 entities), deleting the code in Up/Down (just uses the model snapshot), then update-databased (creates the __MigrationHistory table just fine). I merge this to branch 2 (EXACTLY the same model – exact replica of branch 1), ran update-database with my newly merged migrations and it says Unable to update database to match the current model because there are pending changes. There aren’t pending changes, both models are exactly the same. Is there something I am missing here? I thought I should only run into this issue once migrations are out of whack (merge, model changes from different users).
So why must I do add-migration Initial on both branch 1 and branch 2? They are merged and exactly the same.
Notes: EF 5 (technically 4.4) with .NET 4.0. DevArt dotConnect for Oracle v 8.1.55.0
EDIT: I have read this post but I am not on different platforms, I'm on the same computer - just different branches.
I figured it out, in my initial testing of moving off of EDMX to dotConnect code-first + migrations, I added the schema to the _Mapping files for my fluent mappings. I had to remove this schema. Example:
Instead of:
this.ToTable("ADDRESS", "SCHEMA");
I had to use:
this.ToTable("ADDRESS");
Also I use these options in OnModelCreating:
var config = Devart.Data.Oracle.Entity.Configuration.OracleEntityProviderConfig.Instance;
config.Workarounds.IgnoreDboSchemaName = true;
config.Workarounds.IgnoreSchemaName = true;

Adding a migration in the middle of previous migrations safe?

I have a minor issue which force me to introduce a new migration in between two migrations.
Short version of my question is: whether it is safe to introduce a new migration between previous two.
What I did
I need to have a table which will be filled from a file.
I added a table then imported data on the table by two migrations:
A migration which create a table with named ID column by using self.primary_key = some_id
A migration to import text data onto the table
The issue was, I forgot to add :id => false to the first migration. This cause id column to be created but haven't set correctly. Since I have primary key in some_id it does not cause problem up to now.
Rails 3.2.4
Now, I upgraded to Rails 3.2.4. Due to the change, it look like I need to set unique id before save. Which cause migration 2 above to fail.
The easiest fix is removing id column between above two migrations because I need test suite to build the database from scratch time to time. To make the import to work, I need to fix it before 2nd migration run.
Question
Now the question.
Since above migrations are deployed already, The migration will run after all of the migrations other than the one.
In my case, it looks like Ok to create such a migration (with timestamp in between above two).
Is it okay to do add migration like this way, in this case?

go up to a specific database version in rails

How do I go up to a specific database version from an empty database in rails?
in my case, I did reset the whole database recently, so all tables have been already dropped.
my migration files are as follows:
20111127152636_create_users.rb
20120110100458_create_cars.rb
20120131003026_add_birth_date_to_users.rb
what command do I have to call to get me the second latest version, which is 20120110100458 ?
I have tried "rake db:migrate:up version=20120110100458".
unfortunately, it didn't get me the result I expected it should be; no tables were created at all.
If you want to run the 2 first migrations, use
rake db:migrate VERSION=20120110100458
(it will run 20111127152636_create_users.rb and 20120110100458_create_cars.rb)

Doctrine schema changes while keeping data?

We're developing a Doctrine backed website using YAML to define our schema. Our schema changes regularly (including fk relations) so we need to do a lot of:
Doctrine::generateModelsFromYaml(APPPATH . 'models/yaml', APPPATH . 'models', array('generateTableClasses' => true));
Doctrine::dropDatabases();
Doctrine::createDatabases();
Doctrine::createTablesFromModels();
We would like to keep existing data and store it back in the re-created database. So I copy the data into a temporary database before the main db is dropped.
How do I get the data from the "old-scheme DB copy" to the "new-scheme DB"? (the new scheme only contains NEW columns, NO COLUMNS ARE REMOVED)
NOTE:
This obviously doesn't work because the column count doesn't match.
SELECT * FROM copy.Table INTO newscheme.Table
This obviously does work, however this is consuming too much time to write for every table:
SELECT old.col, old.col2, old.col3,'somenewdefaultvalue' FROM copy.Table as old INTO newscheme.Table
Have you looked into Migrations? They allow you to alter your database schema in programmatical way. WIthout losing data (unless you remove colums, of course)
How about writing a script (using the Doctrine classes for example) which parses the yaml schema files (both the previous version and the "next" version) and generates the sql scripts to run? It would be a one-time job and not require that much work. The benefit of generating manual migration scripts is that you can easily store them in the version control system and replay version steps later on. If that's not something you need, you can just gather up changes in the code and do it directly through the database driver.
Of course, the more fancy your schema changes becomes, the harder the maintenance will get i.e. column name changes, null to not null etc.