-
Notifications
You must be signed in to change notification settings - Fork 3.2k
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Ability to specify database collation #6577
Comments
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. |
EnsureCreatedAsync there, now this item can be found with GitHub search |
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. |
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 [DbContext(typeof(MyDbContext))]
[Migration("00000000000000_SetupDatabase")]
public class SetupDatabase : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
// HACK: there must be a better way
using (var connection = new SqlConnection(MyContextOptions.ConnectionString))
{
connection.Open();
using (var command =
new SqlCommand(
$"ALTER DATABASE [{MyDatabaseName}] COLLATE {MyDefaultCollation}",
connection))
command.ExecuteNonQuery();
SqlConnection.ClearAllPools();
connection.Close();
}
}
} By chance (and I say by chance because as I understand, the Still, having native support on the SQL Server provider for this would be great... something like: migrationBuilder.AlterDatabase().Annotation("COLLATE", "WhateverCollation_CI_AI"); Should work |
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
at least something that disables/enables CI/AI.
|
Issue is open since 2016, any plans to fix this? |
@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. |
@ajcvickers Understood - thank you for the info. |
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. |
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. This looks interesting, I'll try it, thanks :). |
@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. |
Hello everyone, for the moment, my solution is to derive from the SqlServerMigrationsSqlGenerator and override Generate(SqlServerCreateDatabaseOperation, IModel, MigrationCommandListBuilder)
then used it in the DbContext by replacing the IMigrationsSqlGenerator service
|
Consider also character sets--see #15360 |
See also scenario in #15776 |
Also see high-level collations issue #19866 |
Putting into the 5.0 milestone as per our design discussion. |
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. |
* Added metadata and migration support for column- and database- level collations. * Scaffolding implemented for SQL Server. Sqlite seems to not be reporting the collation in pragma_table_info (need newer version?) Closes dotnet#19275 Closes dotnet#6577
* Added metadata and migration support for column- and database- level collations. * Scaffolding implemented for SQL Server. Sqlite seems to not be reporting the collation in pragma_table_info (need newer version?) Closes dotnet#19275 Closes dotnet#6577
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):
So, there should be a proper way to do such things.
See also #6565
The text was updated successfully, but these errors were encountered: