AspNetCore.Docs icon indicating copy to clipboard operation
AspNetCore.Docs copied to clipboard

Migration fails for VS 2017 on MacOS.

Open paulkite opened this issue 8 years ago • 6 comments

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.

paulkite avatar Aug 31 '18 17:08 paulkite

@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.

Rick-Anderson avatar Aug 31 '18 18:08 Rick-Anderson

@paulkite see Update Main

and use EnsureCreated.

Rick-Anderson avatar Aug 31 '18 18:08 Rick-Anderson

@paulkite I'll get this updated in the next sweep to tell folks using SQLite they can't do migrations. cc @tdykstra

Rick-Anderson avatar Aug 31 '18 18:08 Rick-Anderson

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 avatar Feb 01 '19 00:02 robertmarriott

@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

Rick-Anderson avatar Feb 01 '19 02:02 Rick-Anderson

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("Rating"); to RazorPagesMovieContextModelSnapshot.cs. That fixed the SQL error.

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.

robertmarriott avatar Feb 02 '19 01:02 robertmarriott