c# - SQLite 不支持此迁移操作 ('AlterColumnOperation')
问题描述
这是我的 DbContext:
using DatingApp.API.Models;
using Microsoft.EntityFrameworkCore;
namespace DatingApp.API.Data
{
public class DataContext : DbContext
{
public DataContext(DbContextOptions<DataContext> options) : base(options){ }
public DbSet<Value> Values { get; set; }
public DbSet<User> User { get; set; }
public DbSet<Photo> Photos { get; set; }
}
}
这是我生成的文件迁移:
using System;
using Microsoft.EntityFrameworkCore.Migrations;
namespace DatingApp.API.Migrations
{
public partial class ExtendedUserClass : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AlterColumn<string>(
name: "Username",
table: "User",
nullable: true,
oldClrType: typeof(int));
migrationBuilder.AddColumn<string>(
name: "City",
table: "User",
nullable: true);
migrationBuilder.AddColumn<string>(
name: "Country",
table: "User",
nullable: true);
migrationBuilder.AddColumn<DateTime>(
name: "Created",
table: "User",
nullable: false,
defaultValue: new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified));
migrationBuilder.AddColumn<DateTime>(
name: "DateOfBirth",
table: "User",
nullable: false,
defaultValue: new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified));
migrationBuilder.AddColumn<string>(
name: "Gender",
table: "User",
nullable: true);
migrationBuilder.AddColumn<string>(
name: "Interests",
table: "User",
nullable: true);
migrationBuilder.AddColumn<string>(
name: "Introduction",
table: "User",
nullable: true);
migrationBuilder.AddColumn<string>(
name: "KnownAs",
table: "User",
nullable: true);
migrationBuilder.AddColumn<DateTime>(
name: "LastActive",
table: "User",
nullable: false,
defaultValue: new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified));
migrationBuilder.AddColumn<string>(
name: "LookingFor",
table: "User",
nullable: true);
migrationBuilder.CreateTable(
name: "Photos",
columns: table => new
{
Id = table.Column<int>(nullable: false)
.Annotation("Sqlite:Autoincrement", true),
Url = table.Column<string>(nullable: true),
Description = table.Column<string>(nullable: true),
DateAdded = table.Column<DateTime>(nullable: false),
IsMain = table.Column<bool>(nullable: false),
UserId = table.Column<int>(nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Photos", x => x.Id);
table.ForeignKey(
name: "FK_Photos_User_UserId",
column: x => x.UserId,
principalTable: "User",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateIndex(
name: "IX_Photos_UserId",
table: "Photos",
column: "UserId");
}
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "Photos");
migrationBuilder.DropColumn(
name: "City",
table: "User");
migrationBuilder.DropColumn(
name: "Country",
table: "User");
migrationBuilder.DropColumn(
name: "Created",
table: "User");
migrationBuilder.DropColumn(
name: "DateOfBirth",
table: "User");
migrationBuilder.DropColumn(
name: "Gender",
table: "User");
migrationBuilder.DropColumn(
name: "Interests",
table: "User");
migrationBuilder.DropColumn(
name: "Introduction",
table: "User");
migrationBuilder.DropColumn(
name: "KnownAs",
table: "User");
migrationBuilder.DropColumn(
name: "LastActive",
table: "User");
migrationBuilder.DropColumn(
name: "LookingFor",
table: "User");
migrationBuilder.AlterColumn<int>(
name: "Username",
table: "User",
nullable: false,
oldClrType: typeof(string),
oldNullable: true);
}
}
}
尝试删除我更新的数据库迁移,从头添加迁移,尝试执行 dotnet ef database update 命令并得到消息:
SQLite does not support this migration operation ('AlterColumnOperation'). For more information, see http://go.microsoft.com/fwlink/?LinkId=723262.
我不知道该怎么做才能在 SQL lite 中添加迁移,这就是问题出现的原因。
如何更改列?因为大概就是这样。
解决方案
您可以删除数据库和所有现有迁移并再次运行,add-migration InitialCreate
这将从头开始创建新迁移,因此不会有任何列需要更改。
推荐阅读
- c# - 在 ListView 列中创建 CheckBox
- docker - 无法从 docker 容器内部发送邮件
- sql - 使用“INSERT OVERWRITE”使用 databricks delta 更改数据捕获
- java - 如何基于 feign.Response 抛出异常?
- url - 通过 JxBrowser 发布请求不会交出数据
- ios - 是否可以在 UICollectionView 下有一个 UITableView?
- .net - 无论使用 TLS 1.1 的 .net 代码如何,都使用 TLS 1.2
- java - 如何按嵌套地图值对外部地图进行排序
- javascript - Vue.js:v-for 循环中的值未与正确的数组项保持一致
- javascript - AJAX 上传脚本未捕获引用错误应用未定义