Answer the question
In order to leave comments, you need to log in
Why is the migration not working?
I want to add a migration to the database, but with Update-Database, the migration fails, because it throws an error .
using Microsoft.EntityFrameworkCore.Migrations;
namespace CourseWork.Migrations
{
public partial class InitialCreate : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "Users",
columns: table => new
{
Id = table.Column<int>(nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
Name = table.Column<string>(maxLength: 30, nullable: false),
Surname = table.Column<string>(maxLength: 30, nullable: false),
Email = table.Column<string>(maxLength: 30, nullable: false),
Town = table.Column<string>(maxLength: 30, nullable: false),
Street = table.Column<string>(maxLength: 30, nullable: false),
Phone = table.Column<int>(maxLength: 30, nullable: false),
Password = table.Column<string>(maxLength: 30, nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Users", x => x.Id);
});
}
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "Users");
}
}
}
// <auto-generated />
using CourseWork;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
namespace CourseWork.Migrations
{
[DbContext(typeof(ApplicationContext))]
partial class ApplicationContextModelSnapshot : ModelSnapshot
{
protected override void BuildModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "3.1.3")
.HasAnnotation("Relational:MaxIdentifierLength", 128)
.HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
modelBuilder.Entity("CourseWork.DataBase.Users", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int")
.HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
b.Property<string>("Email")
.IsRequired()
.HasColumnType("nvarchar(30)")
.HasMaxLength(30);
b.Property<string>("Name")
.IsRequired()
.HasColumnType("nvarchar(30)")
.HasMaxLength(30);
b.Property<string>("Password")
.IsRequired()
.HasColumnType("nvarchar(30)")
.HasMaxLength(30);
b.Property<int>("Phone")
.HasColumnType("int")
.HasMaxLength(30);
b.Property<string>("Street")
.IsRequired()
.HasColumnType("nvarchar(30)")
.HasMaxLength(30);
b.Property<string>("Surname")
.IsRequired()
.HasColumnType("nvarchar(30)")
.HasMaxLength(30);
b.Property<string>("Town")
.IsRequired()
.HasColumnType("nvarchar(30)")
.HasMaxLength(30);
b.HasKey("Id");
b.ToTable("Users");
});
#pragma warning restore 612, 618
}
}
}
migrationBuilder.CreateTable( //Если тут менять метод, то подчеркивает columns, что он его не определяет
name: "Users",
columns: table => new
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question