You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
There is no way to do this at the moment. Database is created with default settings. It is not an issue on most cases, but there is a plenty of specific ones. For example, I have different collation on production server db, then on development machine.
After some research I've come up with workaround. Pretty ugly so far, but at least working
In Migrations\00000000000000_CreateIdentitySchema.cs add
It is ok. But the connection is reset after execution of this first migration so I have to run in separately.
I've come up with the following script (resetdb.cmd):
dotnet ef database update 00000000000000_CreateIdentitySchema
dotnet ef database update
So, there should be a proper way to do such things.
We agree this would be useful. It's lower priority than the other features we are working on now, so moving to the backlog to look at in a future release.
I have a database with some columns collations set to be case sensitive. Now EF build its query with a temp table, but this temp table does not have the collation on the column so on the insert the database server throws an exception.
Until there is a work-around i can not use ef because the regarding columns contain (case sensitive) guids.
Has anyone taken a look into this since Dec 2016? I'm using a different (albeit similar) workaround than the OP so I don't have to apply migrations independently (I just open a connection on the Up method and send the SQL directly) but it's definitely pretty ugly:
[DbContext(typeof(MyDbContext))][Migration("00000000000000_SetupDatabase")]publicclassSetupDatabase:Migration{protectedoverridevoidUp(MigrationBuildermigrationBuilder){// HACK: there must be a better wayusing(varconnection=newSqlConnection(MyContextOptions.ConnectionString)){connection.Open();using(varcommand=newSqlCommand($"ALTER DATABASE [{MyDatabaseName}] COLLATE {MyDefaultCollation}",connection))command.ExecuteNonQuery();SqlConnection.ClearAllPools();connection.Close();}}}
By chance (and I say by chance because as I understand, the MigrationBuilder only builds up the instructions that will be executed later and this could be done at any point in time) when the Up on this first migration is called, the database is already created but no tables have been created yet.
Still, having native support on the SQL Server provider for this would be great... something like:
@RedDeathGitHub This issue is in the Backlog milestone. This means that it is not going to happen for the 3.0 release. We will re-assess the backlog following the 3.0 release and consider this item at that time. However, keep in mind that there are many other high priority features with which it will be competing for resources.
Before I was creating the Db manually earlier, but I run into "interesting" issue where just after creation - the Db did not accept connections yet. So migrations would try to create an existing Db.
Mostly an issue with testing and local environments but still a nasty one.
@RedDeathGitHub - That is SqlServer behavior. After creating brand new database, it does not allow you to connect to it immediately. (Log in failed for user, which EF core uses as clue to non-existent database). We have also seen the same issue in our tests and have wait time and retry logic for that.
Note: am using this issue to track database collation (both at creation time and later alteration). For other database-creation settings, please open separate issues for the specific feature you're missing.
Activity
rowanmiller commentedon Sep 23, 2016
We agree this would be useful. It's lower priority than the other features we are working on now, so moving to the backlog to look at in a future release.
Ciantic commentedon Sep 24, 2016
EnsureCreatedAsync there, now this item can be found with GitHub search
seriouz commentedon Dec 1, 2016
I have a database with some columns collations set to be case sensitive. Now EF build its query with a temp table, but this temp table does not have the collation on the column so on the insert the database server throws an exception.
Until there is a work-around i can not use ef because the regarding columns contain (case sensitive) guids.
divega commentedon Dec 1, 2016
@seriouz thanks for reporting this. I have created a new issue at #7172. Please add more relevant details there.
javiercampos commentedon Jan 19, 2018
Has anyone taken a look into this since Dec 2016? I'm using a different (albeit similar) workaround than the OP so I don't have to apply migrations independently (I just open a connection on the
Upmethod and send the SQL directly) but it's definitely pretty ugly:By chance (and I say by chance because as I understand, the
MigrationBuilderonly builds up the instructions that will be executed later and this could be done at any point in time) when theUpon this first migration is called, the database is already created but no tables have been created yet.Still, having native support on the SQL Server provider for this would be great... something like:
Should work
murilosdv commentedon Dec 8, 2018
Do we have an update on this? I'll try this workaround but it would be great to have something configurable to do so.
Something more stylish as
modelBuilder.Collation("Whatever_CI_AI")at least something that disables/enables CI/AI.
modelBuilder.IsCollationSensitive(false)or something.RedDeathGitHub commentedon Jan 9, 2019
Issue is open since 2016, any plans to fix this?
ajcvickers commentedon Jan 9, 2019
@RedDeathGitHub This issue is in the Backlog milestone. This means that it is not going to happen for the 3.0 release. We will re-assess the backlog following the 3.0 release and consider this item at that time. However, keep in mind that there are many other high priority features with which it will be competing for resources.
RedDeathGitHub commentedon Jan 9, 2019
@ajcvickers Understood - thank you for the info.
murilosdv commentedon Jan 9, 2019
Well, I created an extension using some examples I found and I've come up with this.
And after creating your first migration just add the information on the top.
It's working by just using Update-Database, works for me for now.
RedDeathGitHub commentedon Jan 10, 2019
Before I was creating the Db manually earlier, but I run into "interesting" issue where just after creation - the Db did not accept connections yet. So migrations would try to create an existing Db.
Mostly an issue with testing and local environments but still a nasty one.
This looks interesting, I'll try it, thanks :).
smitpatel commentedon Jan 10, 2019
@RedDeathGitHub - That is SqlServer behavior. After creating brand new database, it does not allow you to connect to it immediately. (Log in failed for user, which EF core uses as clue to non-existent database). We have also seen the same issue in our tests and have wait time and retry logic for that.
9 remaining items
[-]Ability to specify collation and other db params upon creation[/-][+]Ability to specify database collation[/+]roji commentedon Apr 11, 2020
Note: am using this issue to track database collation (both at creation time and later alteration). For other database-creation settings, please open separate issues for the specific feature you're missing.
Support specifying collations on columns and databases
Support specifying collations on columns and databases
Support specifying collations on columns and databases (#20602)