简体   繁体   中英

SQLite does not support this migration operation ('DropForeignKeyOperation')

I'm building a web API using Asp.Net core 3.0 with EFcore. I'm using code first approach. I did my initial migration with this model

  public class Group {
    [Key]
    public int Id{get;set;}
    public string Title { get; set; }
   }

Later I added a foreign key relationship to this model

  public class Group {
    [Key]
    public int Id{get;set;}
    public string Title { get; set; }

    [ForeignKey("UserId")]
    public User User { get; set; }
    public int UserId { get; set; }
   }

The new migrations generates properly when I run Add-Migration <migrationName> on PMC . But when I run update-database I get this error: SQLite does not support this migration operation ('DropForeignKeyOperation')

This is a documented limitation of the SQLite Database Provider:

Workaround (Source: MSDN )

You can workaround some of these limitations by manually writing code in your migrations to perform a table rebuild. A table rebuild involves renaming the existing table, creating a new table, copying data to the new table, and dropping the old table. You will need to use the Sql(string) method to perform some of these steps.

Edit : As directed by @Shawn it seems MSDN is out of date and this is a malpractice. Instead use the Sql(string) method to issue an ALTER TABLE statement as documented here .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM