Migration fails for VS 2017 on MacOS.
I ran the following commands in Terminal for MacOS to attempt to migrate the database.
dotnet ef migrations add Rating
dotnet ef database update
When the migration runs it throws an exception for the newly added field.
System.NotSupportedException: SQLite does not support this migration operation ('AlterColumnOperation'). For more information, see http://go.microsoft.com/fwlink/?LinkId=723262.
at Microsoft.EntityFrameworkCore.Migrations.SqliteMigrationsSqlGenerator.Generate(AlterColumnOperation operation, IModel model, MigrationCommandListBuilder builder)
at Microsoft.EntityFrameworkCore.Migrations.MigrationsSqlGenerator.Generate(MigrationOperation operation, IModel model, MigrationCommandListBuilder builder)
at Microsoft.EntityFrameworkCore.Migrations.MigrationsSqlGenerator.Generate(IReadOnlyList`1 operations, IModel model)
at Microsoft.EntityFrameworkCore.Migrations.Internal.Migrator.GenerateUpSql(Migration migration)
at Microsoft.EntityFrameworkCore.Migrations.Internal.Migrator.Migrate(String targetMigration)
at Microsoft.EntityFrameworkCore.Design.Internal.MigrationsOperations.UpdateDatabase(String targetMigration, String contextType)
at Microsoft.EntityFrameworkCore.Design.OperationExecutor.UpdateDatabase.<>c__DisplayClass0_1.<.ctor>b__0()
at Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase.Execute(Action action)
SQLite does not support this migration operation ('AlterColumnOperation'). For more information, see http://go.microsoft.com/fwlink/?LinkId=723262.
What I ended up doing instead was to run dotnet ef migrations remove to unstage my migration and then dotnet ef migrations drop to drop the database.
To complete this section so I could move on in the tutorial I updated the "<Date>_InitialCreate.cs" and "<Date>_InitialCreate_Designer.cs" to add the requires Rating field. App built and ran fine after this.
If there's another way to accomplish this part of the tutorial I'd love to know. I understand this is the Windows VS piece of the tutorial, but they route the Mac version to this piece of the tutorial as documentation for the Mac version hasn't been completed.
Thanks!
Document Details
⚠ Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.
- ID: 01013ef6-c55c-ff58-571c-ddc4435993af
- Version Independent ID: 24699fe5-9744-1796-0798-f7b211ec0f2f
- Content: Add a new field to a Razor Page in ASP.NET Core
- Content Source: aspnetcore/tutorials/razor-pages/new-field.md
- Product: aspnet-core
- GitHub Login: @Rick-Anderson
- Microsoft Alias: riande
@paulkite great error message:
System.NotSupportedException: SQLite does not support this migration operation ('AlterColumnOperation')
That says it all.
To finish the tutorial, Don't do migrations.
@paulkite I'll get this updated in the next sweep to tell folks using SQLite they can't do migrations. cc @tdykstra
This really should be mentioned early in the tutorial, like "You can use SQLite but be aware that ..."
I just got to the point where I received the error mentioned above. I then deleted my database and was still unable to run the migrations. I then performed the solution suggested by @paulkite, but unfortunately it's not working for me. The database says it updated, but I then get a SQL error saying the Rating column wasn't found when I run the application.
Migrations are fundamental to working with an ORM. If one can't use migrations with SQLite, then that database is pretty much useless for this application. Had I known this, I would have used MySQL, or I would have done the tutorial on Windows using SQL Server Express.
All in all, this is a great tutorial, but it's kind of frustrating to run into a limitation like this right at the end.
@robertmarriott I agree. Can you open a new issue on the page you think this should be introduced at? That will get this addressed more quickly.
You can do migrations with SQLite, but you have to do some custom work.
The easiest way to get around this is change the connection string. That uses a new DB. SQLite has some quirks about deleting a DB, we should probably doc that.
Thanks for taking the time to report this. cc @tdykstra
Thanks for the quick reply, @Rick-Anderson. I was able to get @paulkite's solution to work. After commenting here, I realized I needed to add b.Property
I've often used SQLite for quick prototyping in Laravel. The Eloquent ORM migrations always seemed to work okay. But as you mentioned, there are some limitations with SQLite, so probably better to use MySQL or Postgres on Mac.