Laden...

Fehler bei der Erstellung der Datenbank "Incorrect syntax near the keyword 'NOT'."

Erstellt von GrilleGsutav vor 6 Jahren Letzter Beitrag vor 6 Jahren 36.089 Views
G
GrilleGsutav Themenstarter:in
27 Beiträge seit 2017
vor 6 Jahren
Fehler bei der Erstellung der Datenbank "Incorrect syntax near the keyword 'NOT'."

verwendetes Datenbanksystem: <Microsoft SQL Server>

Hi,

Habe folgendes Problem.
Hab in ASP.neet Core MVC meine Models mit "Code First" Ansatz erstellt.
Nun habe ich mit Entity-Framework Core "add- migration" ausgefürht.
Beim "Update-Database" tritt volgender fehler auf:

Fehlermeldung:
Incorrect syntax near the keyword 'NOT'.

Finde aber keine fehler.

Meine DbContext Datei:


using aquarium.Models;
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.ComponentModel.DataAnnotations;

namespace aquarium.Context
{
  public class AquariumContext : DbContext
  {
    public AquariumContext(DbContextOptions<AquariumContext> options) : base(options)
    { }

    public DbSet<LightCourse> Light { get; set; }
    public DbSet<Pool> Pool { get; set; }
    public DbSet<ShrimpImages> ShrimpImages { get; set; }
    public DbSet<Shrimps> Shrimps { get; set; }
    public DbSet<TemperatureCourse> Temperature { get; set; }
    public DbSet<UserConfig> UserConfig { get; set; }
    public DbSet<WaterLevels> WaterLevels { get; set; }

    protected override void OnModelCreating(ModelBuilder modelBuilder)
    {
      // Shrimps
      modelBuilder.Entity<Shrimps>()
        .Property(b => b.Id)
        .ValueGeneratedOnAdd();

      modelBuilder.Entity<Shrimps>()
        .HasKey(b => b.GermanName);

      modelBuilder.Entity<Shrimps>()
        .Property(b => b.Id)
        .HasColumnType("varchar(30)");

      modelBuilder.Entity<Shrimps>()
        .Property(b => b.ScientificName)
        .HasColumnType("varchar(100)")
        .IsRequired();

      modelBuilder.Entity<Shrimps>()
        .Property(b => b.Origin)
        .HasColumnType("varchar(100)")
        .IsRequired();

      modelBuilder.Entity<Shrimps>()
        .Property(b => b.Size)
        .HasColumnType("decimal(4)");

      modelBuilder.Entity<Shrimps>()
        .Property(b => b.LifeSpan)
        .HasColumnType("varchar(10)")
        .IsRequired();

      modelBuilder.Entity<Shrimps>()
        .Property(b => b.Family)
        .HasColumnType("varchar(100)");

      modelBuilder.Entity<Shrimps>()
        .HasMany(b => b.Pool)
        .WithOne(b => b.Shrimps);

      // LightCourse

      modelBuilder.Entity<LightCourse>()
        .HasKey(b => b.Id);

      modelBuilder.Entity<LightCourse>()
        .Property(b => b.StateTime)
        .HasColumnType("datetime2(7)")
        .HasComputedColumnSql("GetUtcDate()");

      modelBuilder.Entity<LightCourse>()
        .HasMany(b => b.Pool)
        .WithOne(b => b.LightCourse);

      // Pool

      modelBuilder.Entity<Pool>()
        .HasKey(b => b.Id);

      modelBuilder.Entity<Pool>()
        .Property(b => b.Width)
        .HasColumnType("decimal(5,2)")
        .IsRequired();

      modelBuilder.Entity<Pool>()
        .Property(b => b.Height)
        .HasColumnType("decimal(5,2)")
        .IsRequired();

      modelBuilder.Entity<Pool>()
        .Property(b => b.Depth)
        .HasColumnType("decimal(5,2)")
        .IsRequired();

      // ShrimpImages

      modelBuilder.Entity<ShrimpImages>()
        .HasKey(b => b.Id);

      modelBuilder.Entity<ShrimpImages>()
        .Property(b => b.ImageName)
        .HasColumnType("varchar(100)")
        .IsRequired();

      modelBuilder.Entity<ShrimpImages>()
        .Property(b => b.CreationDate)
        .HasColumnType("datetime2(7)")
        .HasComputedColumnSql("GetUtcDate()");

      modelBuilder.Entity<ShrimpImages>()
        .HasOne(b => b.Shrimps)
        .WithMany(b => b.ShrimpImages);

      modelBuilder.Entity<ShrimpImages>()
        .Property(b => b.Discription)
        .HasColumnType("varchar(600)");

      // TemperatureCourse

      modelBuilder.Entity<TemperatureCourse>()
        .HasKey(b => b.Id);

      modelBuilder.Entity<TemperatureCourse>()
        .Property(b => b.Temp)
        .HasColumnType("decimal(5,2)")
        .IsRequired();

      modelBuilder.Entity<TemperatureCourse>()
        .Property(b => b.TimeState)
        .HasColumnType("datetime2(7)")
        .HasComputedColumnSql("GetUtcDate()");

      modelBuilder.Entity<TemperatureCourse>()
        .HasOne(b => b.Pool)
        .WithOne(b => b.TemperatureCourse);

      // UserConfig

      modelBuilder.Entity<UserConfig>()
        .HasKey(b => b.Id);

      modelBuilder.Entity<UserConfig>()
        .Property(b => b.Firstname)
        .HasColumnType("varchar(20)")
        .IsRequired();

      modelBuilder.Entity<UserConfig>()
        .Property(b => b.Lastname)
        .HasColumnType("varchar(20)")
        .IsRequired();

      modelBuilder.Entity<UserConfig>()
        .Property(b => b.Nickname)
        .HasColumnType("varchar(20)")
        .IsRequired();

      modelBuilder.Entity<UserConfig>()
        .Property(b => b.TemperatureUnit)
        .HasColumnType("varchar(1)")
        .IsRequired();

      // WaterLevels

      modelBuilder.Entity<WaterLevels>()
        .HasKey(b => b.ShrimpId);

      modelBuilder.Entity<WaterLevels>()
        .Property(b => b.TemperatureMax)
        .HasColumnType("decimal(5,2)")
        .IsRequired();

      modelBuilder.Entity<WaterLevels>()
        .Property(b => b.TemperatureMin)
        .HasColumnType("decimal(5,2")
        .IsRequired();

      modelBuilder.Entity<WaterLevels>()
        .Property(b => b.PhWertMax)
        .HasColumnType("decimal(5,2)")
        .IsRequired();

      modelBuilder.Entity<WaterLevels>()
        .Property(b => b.PhWertMin)
        .HasColumnType("decimal(5,2)")
        .IsRequired();

      modelBuilder.Entity<WaterLevels>()
        .Property(b => b.TotalHardnessMax)
        .HasColumnType("decimal(5,2)")
        .IsRequired();

      modelBuilder.Entity<WaterLevels>()
        .Property(b => b.TotalHardnessMin)
        .HasColumnType("decimal(5,2)")
        .IsRequired();

      modelBuilder.Entity<WaterLevels>()
        .Property(b => b.CarbonateMax)
        .HasColumnType("decimal(5,2)")
        .IsRequired();

      modelBuilder.Entity<WaterLevels>()
        .Property(b => b.CarbonateMin)
        .HasColumnType("decimal(5,2)")
        .IsRequired();

      modelBuilder.Entity<WaterLevels>()
        .Property(b => b.ConductanceMax)
        .HasColumnType("decimal(5,2)")
        .IsRequired();

      modelBuilder.Entity<WaterLevels>()
        .Property(b => b.ConductanceMin)
        .HasColumnType("decimal(5,2)")
        .IsRequired();

      modelBuilder.Entity<WaterLevels>()
        .HasMany(b => b.Shrimps)
        .WithOne(b => b.WaterLevels);
    }
  }
}

Die Migration Dtei die EF-Core erstellt hat:


using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Migrations;
using System;
using System.Collections.Generic;

namespace aquarium.Migrations
{
    public partial class initialDatabase : Migration
    {
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.CreateTable(
                name: "Light",
                columns: table => new
                {
                    Id = table.Column<int>(type: "int", nullable: false)
                        .Annotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn),
                    State = table.Column<byte>(type: "tinyint", nullable: false),
                    StateTime = table.Column<DateTime>(type: "datetime2(7)", nullable: false, computedColumnSql: "GetUtcDate()")
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_Light", x => x.Id);
                });

            migrationBuilder.CreateTable(
                name: "Temperature",
                columns: table => new
                {
                    Id = table.Column<string>(type: "nvarchar(450)", nullable: false),
                    Temp = table.Column<double>(type: "decimal(5,2)", nullable: false),
                    TimeState = table.Column<DateTime>(type: "datetime2(7)", nullable: false, computedColumnSql: "GetUtcDate()")
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_Temperature", x => x.Id);
                });

            migrationBuilder.CreateTable(
                name: "UserConfig",
                columns: table => new
                {
                    Id = table.Column<int>(type: "int", nullable: false)
                        .Annotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn),
                    Firstname = table.Column<string>(type: "varchar(20)", nullable: false),
                    Lastname = table.Column<string>(type: "varchar(20)", nullable: false),
                    Nickname = table.Column<string>(type: "varchar(20)", nullable: false),
                    TemperatureUnit = table.Column<bool>(type: "varchar(1)", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_UserConfig", x => x.Id);
                });

            migrationBuilder.CreateTable(
                name: "WaterLevels",
                columns: table => new
                {
                    ShrimpId = table.Column<int>(type: "int", nullable: false)
                        .Annotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn),
                    CarbonateMax = table.Column<decimal>(type: "decimal(5,2)", nullable: false),
                    CarbonateMin = table.Column<decimal>(type: "decimal(5,2)", nullable: false),
                    ConductanceMax = table.Column<decimal>(type: "decimal(5,2)", nullable: false),
                    ConductanceMin = table.Column<decimal>(type: "decimal(5,2)", nullable: false),
                    PhWertMax = table.Column<decimal>(type: "decimal(5,2)", nullable: false),
                    PhWertMin = table.Column<decimal>(type: "decimal(5,2)", nullable: false),
                    TemperatureMax = table.Column<decimal>(type: "decimal(5,2)", nullable: false),
                    TemperatureMin = table.Column<decimal>(type: "decimal(5,2", nullable: false),
                    TotalHardnessMax = table.Column<decimal>(type: "decimal(5,2)", nullable: false),
                    TotalHardnessMin = table.Column<decimal>(type: "decimal(5,2)", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_WaterLevels", x => x.ShrimpId);
                });

            migrationBuilder.CreateTable(
                name: "Shrimps",
                columns: table => new
                {
                    GermanName = table.Column<string>(type: "nvarchar(450)", nullable: false),
                    Family = table.Column<string>(type: "varchar(100)", nullable: true),
                    Id = table.Column<int>(type: "varchar(30)", nullable: false)
                        .Annotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn),
                    LifeSpan = table.Column<string>(type: "varchar(10)", nullable: false),
                    Origin = table.Column<string>(type: "varchar(100)", nullable: false),
                    ScientificName = table.Column<string>(type: "varchar(100)", nullable: false),
                    Size = table.Column<decimal>(type: "decimal(4)", nullable: true),
                    WaterLevelsShrimpId = table.Column<int>(type: "int", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_Shrimps", x => x.GermanName);
                    table.ForeignKey(
                        name: "FK_Shrimps_WaterLevels_WaterLevelsShrimpId",
                        column: x => x.WaterLevelsShrimpId,
                        principalTable: "WaterLevels",
                        principalColumn: "ShrimpId",
                        onDelete: ReferentialAction.Restrict);
                });

            migrationBuilder.CreateTable(
                name: "Pool",
                columns: table => new
                {
                    Id = table.Column<int>(type: "int", nullable: false)
                        .Annotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn),
                    Depth = table.Column<double>(type: "decimal(5,2)", nullable: false),
                    Height = table.Column<double>(type: "decimal(5,2)", nullable: false),
                    LightCourseId = table.Column<int>(type: "int", nullable: true),
                    ShrimpsGermanName = table.Column<string>(type: "nvarchar(450)", nullable: true),
                    TemperatureCourseId = table.Column<string>(type: "nvarchar(450)", nullable: true),
                    Volume = table.Column<double>(type: "float", nullable: false),
                    Width = table.Column<double>(type: "decimal(5,2)", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_Pool", x => x.Id);
                    table.ForeignKey(
                        name: "FK_Pool_Light_LightCourseId",
                        column: x => x.LightCourseId,
                        principalTable: "Light",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Restrict);
                    table.ForeignKey(
                        name: "FK_Pool_Shrimps_ShrimpsGermanName",
                        column: x => x.ShrimpsGermanName,
                        principalTable: "Shrimps",
                        principalColumn: "GermanName",
                        onDelete: ReferentialAction.Restrict);
                    table.ForeignKey(
                        name: "FK_Pool_Temperature_TemperatureCourseId",
                        column: x => x.TemperatureCourseId,
                        principalTable: "Temperature",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Restrict);
                });

            migrationBuilder.CreateTable(
                name: "ShrimpImages",
                columns: table => new
                {
                    Id = table.Column<int>(type: "int", nullable: false)
                        .Annotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn),
                    CreationDate = table.Column<DateTime>(type: "datetime2(7)", nullable: false, computedColumnSql: "GetUtcDate()"),
                    Discription = table.Column<string>(type: "varchar(600)", nullable: true),
                    ImageName = table.Column<string>(type: "varchar(100)", nullable: false),
                    ShrimpsGermanName = table.Column<string>(type: "nvarchar(450)", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_ShrimpImages", x => x.Id);
                    table.ForeignKey(
                        name: "FK_ShrimpImages_Shrimps_ShrimpsGermanName",
                        column: x => x.ShrimpsGermanName,
                        principalTable: "Shrimps",
                        principalColumn: "GermanName",
                        onDelete: ReferentialAction.Restrict);
                });

            migrationBuilder.CreateIndex(
                name: "IX_Pool_LightCourseId",
                table: "Pool",
                column: "LightCourseId");

            migrationBuilder.CreateIndex(
                name: "IX_Pool_ShrimpsGermanName",
                table: "Pool",
                column: "ShrimpsGermanName");

            migrationBuilder.CreateIndex(
                name: "IX_Pool_TemperatureCourseId",
                table: "Pool",
                column: "TemperatureCourseId",
                unique: true,
                filter: "[TemperatureCourseId] IS NOT NULL");

            migrationBuilder.CreateIndex(
                name: "IX_ShrimpImages_ShrimpsGermanName",
                table: "ShrimpImages",
                column: "ShrimpsGermanName");

            migrationBuilder.CreateIndex(
                name: "IX_Shrimps_WaterLevelsShrimpId",
                table: "Shrimps",
                column: "WaterLevelsShrimpId");
        }

        protected override void Down(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropTable(
                name: "Pool");

            migrationBuilder.DropTable(
                name: "ShrimpImages");

            migrationBuilder.DropTable(
                name: "UserConfig");

            migrationBuilder.DropTable(
                name: "Light");

            migrationBuilder.DropTable(
                name: "Temperature");

            migrationBuilder.DropTable(
                name: "Shrimps");

            migrationBuilder.DropTable(
                name: "WaterLevels");
        }
    }
}

Und nun die Fehlermeldung:

Fehlermeldung:
Microsoft.AspNetCore.DataProtection.KeyManagement.XmlKeyManager[0]
User profile is available. Using 'C:\Users\ottof\AppData\Local\ASP.NET\DataProtection-Keys' as key repository and Windows DPAPI to encrypt keys at rest.
Microsoft.EntityFrameworkCore.Infrastructure[100403]
Entity Framework Core 2.0.0-rtm-26452 initialized 'AquariumContext' using provider 'Microsoft.EntityFrameworkCore.SqlServer' with options: None
To undo this action, use Remove-Migration.
PM> Update-Database
Microsoft.AspNetCore.DataProtection.KeyManagement.XmlKeyManager[0]
User profile is available. Using 'C:\Users\ottof\AppData\Local\ASP.NET\DataProtection-Keys' as key repository and Windows DPAPI to encrypt keys at rest.
Microsoft.EntityFrameworkCore.Infrastructure[100403]
Entity Framework Core 2.0.0-rtm-26452 initialized 'AquariumContext' using provider 'Microsoft.EntityFrameworkCore.SqlServer' with options: None
Microsoft.EntityFrameworkCore.Database.Command[200101]
Executed DbCommand (23ms) [Parameters=[], CommandType='Text', CommandTimeout='30']
SELECT OBJECT_ID(N'__EFMigrationsHistory');
Microsoft.EntityFrameworkCore.Database.Command[200101]
Executed DbCommand (2ms) [Parameters=[], CommandType='Text', CommandTimeout='30']
SELECT OBJECT_ID(N'__EFMigrationsHistory');
Applying migration '20171022104044_initial-Database'.
Microsoft.EntityFrameworkCore.Database.Command[200101]
Executed DbCommand (5ms) [Parameters=[], CommandType='Text', CommandTimeout='30']
SELECT [MigrationId], [ProductVersion]
FROM [__EFMigrationsHistory]
ORDER BY [MigrationId];
Microsoft.EntityFrameworkCore.Migrations[200402]
Applying migration '20171022104044_initial-Database'.
Microsoft.EntityFrameworkCore.Database.Command[200101]
Executed DbCommand (74ms) [Parameters=[], CommandType='Text', CommandTimeout='30']
CREATE TABLE [Light] (
[Id] int NOT NULL IDENTITY,
[State] tinyint NOT NULL,
[StateTime] AS GetUtcDate(),
CONSTRAINT [PK_Light] PRIMARY KEY ([Id])
);
Microsoft.EntityFrameworkCore.Database.Command[200101]
Executed DbCommand (12ms) [Parameters=[], CommandType='Text', CommandTimeout='30']
CREATE TABLE [Temperature] (
[Id] nvarchar(450) NOT NULL,
[Temp] decimal(5,2) NOT NULL,
[TimeState] AS GetUtcDate(),
CONSTRAINT [PK_Temperature] PRIMARY KEY ([Id])
);
Microsoft.EntityFrameworkCore.Database.Command[200101]
Executed DbCommand (5ms) [Parameters=[], CommandType='Text', CommandTimeout='30']
CREATE TABLE [UserConfig] (
[Id] int NOT NULL IDENTITY,
[Firstname] varchar(20) NOT NULL,
[Lastname] varchar(20) NOT NULL,
[Nickname] varchar(20) NOT NULL,
[TemperatureUnit] varchar(1) NOT NULL,
CONSTRAINT [PK_UserConfig] PRIMARY KEY ([Id])
);
Failed executing DbCommand (8ms) [Parameters=[], CommandType='Text', CommandTimeout='30']
CREATE TABLE [WaterLevels] (
[ShrimpId] int NOT NULL IDENTITY,
[CarbonateMax] decimal(5,2) NOT NULL,
[CarbonateMin] decimal(5,2) NOT NULL,
[ConductanceMax] decimal(5,2) NOT NULL,
[ConductanceMin] decimal(5,2) NOT NULL,
[PhWertMax] decimal(5,2) NOT NULL,
[PhWertMin] decimal(5,2) NOT NULL,
[TemperatureMax] decimal(5,2) NOT NULL,
[TemperatureMin] decimal(5,2 NOT NULL,
[TotalHardnessMax] decimal(5,2) NOT NULL,
[TotalHardnessMin] decimal(5,2) NOT NULL,
CONSTRAINT [PK_WaterLevels] PRIMARY KEY ([ShrimpId])
);
fail: Microsoft.EntityFrameworkCore.Database.Command[200102]
Failed executing DbCommand (8ms) [Parameters=[], CommandType='Text', CommandTimeout='30']
CREATE TABLE [WaterLevels] (
[ShrimpId] int NOT NULL IDENTITY,
[CarbonateMax] decimal(5,2) NOT NULL,
[CarbonateMin] decimal(5,2) NOT NULL,
[ConductanceMax] decimal(5,2) NOT NULL,
[ConductanceMin] decimal(5,2) NOT NULL,
[PhWertMax] decimal(5,2) NOT NULL,
[PhWertMin] decimal(5,2) NOT NULL,
[TemperatureMax] decimal(5,2) NOT NULL,
[TemperatureMin] decimal(5,2 NOT NULL,
[TotalHardnessMax] decimal(5,2) NOT NULL,
[TotalHardnessMin] decimal(5,2) NOT NULL,
CONSTRAINT [PK_WaterLevels] PRIMARY KEY ([ShrimpId])
);
System.Data.SqlClient.SqlException (0x80131904): Incorrect syntax near the keyword 'NOT'.
at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action1 wrapCloseInAction) at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection, Action1 wrapCloseInAction)
at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose)
at System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady)
at System.Data.SqlClient.SqlCommand.RunExecuteNonQueryTds(String methodName, Boolean async, Int32 timeout, Boolean asyncWrite)
at System.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(TaskCompletionSource1 completion, Boolean sendToPipe, Int32 timeout, Boolean asyncWrite, String methodName) at System.Data.SqlClient.SqlCommand.ExecuteNonQuery() at Microsoft.EntityFrameworkCore.Storage.Internal.RelationalCommand.Execute(IRelationalConnection connection, DbCommandMethod executeMethod, IReadOnlyDictionary2 parameterValues)
ClientConnectionId:d9f453b4-cbcf-45cf-97fb-af7a0aa22e5a
Error Number:156,State:1,Class:15
System.Data.SqlClient.SqlException (0x80131904): Incorrect syntax near the keyword 'NOT'.
at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action1 wrapCloseInAction) at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection, Action1 wrapCloseInAction)
at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose)
at System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady)
at System.Data.SqlClient.SqlCommand.RunExecuteNonQueryTds(String methodName, Boolean async, Int32 timeout, Boolean asyncWrite)
at System.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(TaskCompletionSource1 completion, Boolean sendToPipe, Int32 timeout, Boolean asyncWrite, String methodName) at System.Data.SqlClient.SqlCommand.ExecuteNonQuery() at Microsoft.EntityFrameworkCore.Storage.Internal.RelationalCommand.Execute(IRelationalConnection connection, DbCommandMethod executeMethod, IReadOnlyDictionary2 parameterValues)
at Microsoft.EntityFrameworkCore.Storage.Internal.RelationalCommand.ExecuteNonQuery(IRelationalConnection connection, IReadOnlyDictionary2 parameterValues) at Microsoft.EntityFrameworkCore.Migrations.MigrationCommand.ExecuteNonQuery(IRelationalConnection connection, IReadOnlyDictionary2 parameterValues)
at Microsoft.EntityFrameworkCore.Migrations.Internal.MigrationCommandExecutor.ExecuteNonQuery(IEnumerable`1 migrationCommands, IRelationalConnection connection)
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)
ClientConnectionId:d9f453b4-cbcf-45cf-97fb-af7a0aa22e5a
Error Number:156,State:1,Class:15
Incorrect syntax near the keyword 'NOT'.

Bin noch nicht so erfahren mit Entity-Framework Core.

Wenn wer ne idee hat bitte posten!

Herzlichen Dank

Fabian

P
441 Beiträge seit 2014
vor 6 Jahren

Hi,

gibt es einen Grund, warum du die Spaltentypen für die Datenbank selber festlegst?
Hier liegt nämlich auch der Fehler:


modelBuilder.Entity<WaterLevels>()
        .Property(b => b.TemperatureMin)
        .HasColumnType("decimal(5,2")
        .IsRequired();

Denn die Typen erkennen kann EF von alleine.

G
GrilleGsutav Themenstarter:in
27 Beiträge seit 2017
vor 6 Jahren

Danke,

Dann werd ich das mal weglassen.
Dachte nur das es sauberer ist wenn ich alles selber festlege

Gruß

Fabi

2.207 Beiträge seit 2011
vor 6 Jahren

Hallo GrilleGsutav,

bitte beachte auch in Zukunft [Hinweis] Wie poste ich richtig? 4.1 " Postet stattdessen bitte nur den relevanten Code direkt im Beitrag." und bitte benutze die richtigen Code-Tags.

Gruss

Coffeebean

G
GrilleGsutav Themenstarter:in
27 Beiträge seit 2017
vor 6 Jahren

Werd ich machen !

Gruß

Fabi