Drop/create SQLite columns when changing column type to something not convertible
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 25/100
Research direction
Reproduce the failure using the linked test project and the migration created after changing Post.Id from Guid to Int32. Start at the migration execution triggered by context.Database.Migrate() in Test/Program.cs line 14, then inspect the generated SQLite migration and its table-rebuild operations. Done means the migration handles a non-convertible column change without the datatype mismatch exception.
Written by the indexing model from the issue text.
Description
Hello.
I have simple class library project with a EF Core 5.0-rc1 DbContext that targets .NET 5.0-preview7 (I'm using .NET 5-preview7 because according to info on download page it is the latest one that supports Visual Studio 2019 v16.7 Release. I use only stable IDE builds in my project and cannot use preview IDE versions).
I've have following entites
public class User
{
public Guid Id { get; set; }
public String Name { get; set; }
public Int32 Age { get; set; }
public virtual IList<Post> Posts { get; set; }
}
public class Post
{
public Guid Id { get; set; }
public String Text { get; set; }
public DateTime PostDate { get; set; }
public Guid UserId { get; set; }
public virtual User User { get; set; }
}
Then I've added first migration via dotnet ef migrations add InitialCreate command, created test database and populated some data.
After that I've changed Post.Id data type from Guid to Int32 and created second migration.
According to this SQLite migrations table rebuilds are now available since EF Core 5.0.0-preview8.
Also according to docs AlterColumn command should work for SQLite via table rebuild.
But running context.Database.Migrate(); throws an exception
SQLite Error 20: 'datatype mismatch'.'
Steps to reproduce
- Download test project - https://yadi.sk/d/iZiJnlidwyNMlg (test database test.db with some data is already placed in program output folder).
- Compile and run Test console application -
context.Database.Migrate();throws an exception
Exception StackTrace:
at Microsoft.Data.Sqlite.SqliteException.ThrowExceptionForRC(Int32 rc, sqlite3 db)
at Microsoft.Data.Sqlite.SqliteDataReader.NextResult()
at Microsoft.Data.Sqlite.SqliteCommand.ExecuteReader(CommandBehavior behavior)
at Microsoft.Data.Sqlite.SqliteCommand.ExecuteReader()
at Microsoft.Data.Sqlite.SqliteCommand.ExecuteNonQuery()
at Microsoft.EntityFrameworkCore.Storage.RelationalCommand.ExecuteNonQuery(RelationalCommandParameterObject parameterObject)
at Microsoft.EntityFrameworkCore.Migrations.MigrationCommand.ExecuteNonQuery(IRelationalConnection connection, IReadOnlyDictionary`2 parameterValues)
at Microsoft.EntityFrameworkCore.Migrations.Internal.MigrationCommandExecutor.ExecuteNonQuery(IEnumerable`1 migrationCommands, IRelationalConnection connection)
at Microsoft.EntityFrameworkCore.Migrations.Internal.Migrator.Migrate(String targetMigration)
at Microsoft.EntityFrameworkCore.RelationalDatabaseFacadeExtensions.Migrate(DatabaseFacade databaseFacade)
at Test.Program.Main(String[] args) in D:\Test\Test\Program.cs:line 14
Further technical details
EF Core version: 5.0-rc1
Database provider: Microsoft.EntityFrameworkCore.Sqlite 5.0-rc1
Target framework: .NET 5.0-preview7
Operating system: Windows 10 2004 x64
IDE: Visual Studio 2019 16.7.3 Professional
- Dominant language
- C#
- Stars
- 14.8k
- Forks
- 3.4k
- Avg merge
- 2d 5h
- Merged PRs (30d)
- 134
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from dotnet/efcore
-
Difficulty 4/5 3-5 days Newbie friendliness 55/100
-
customer-reported
Difficulty 5/5 Over a week Newbie friendliness 38/100
-
area-cosmos area-vector-search
Difficulty 5/5 Over a week Newbie friendliness 25/100
-
area-cosmos
Difficulty 5/5 Over a week Newbie friendliness 25/100
-
area-tools needs-design
Difficulty 4/5 3-5 days Newbie friendliness 25/100
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 86/100
-
:watch: Not Triaged 11.0 fundamentals/subsvc
Difficulty 2/5 1-3 hours Newbie friendliness 92/100
dotnet/AspNetCore.Docs#37699 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
SubtitleEdit/subtitleedit#15108 · 1 comment ·
-
area/docs-content Bug pulumi/docs
Difficulty 1/5 1-3 hours Newbie friendliness 94/100
-
agentic-workflows untriaged
Difficulty 2/5 1-3 hours Newbie friendliness 76/100