Ошибка с обновлением базы данных по технологии asp.net

Я создал несколько таблиц. Вот первая из них:

namespace Security_Agency.Models { public class Employees {

    public int Id { get; set; }
    [Display (Name = "ФИО")]
    [Required(ErrorMessage = "Поле 'ФИО' обязательно для заполнения.")]
    public string full_name { get; set; }
    [Display(Name = "Должность")]
    [Required(ErrorMessage = "Поле 'Должность' обязательно для заполнения.")]
    public string position {  get; set; }
    [Display(Name = "Дата поступления на работу")]
    [DataType(DataType.Date)]
    [DisplayFormat(DataFormatString = "{0:yyyy-MM-dd}", ApplyFormatInEditMode = true)]
    public DateTime hire_date { get; set; }
    [Display(Name = "Зарплата")]
    [Range(0, int.MaxValue, ErrorMessage = "Зарплата должна быть неотрицательным числом.")]
    public int salary {  get; set; }
    [Display(Name = "Образование")]
    public string education { get; set; }

    [ForeignKey("Secured_Objects")]
    public  int? Secured_ObjectsId { get; set; }
    public Secured_Objects Secured_Objects { get; set; }
      
}

} И вот вторая: { public class Secured_Objects { public int Id { get; set; }

    [Display(Name = "Адрес")]
    [Required(ErrorMessage = "Поле 'Адрес' обязательно для заполнения.")]
    public string adress { get; set; }

    [Display(Name = "Серийный номер объекта")]

    [Required(ErrorMessage = "Поле 'Серийный номер объекта' обязательно для заполнения.")]
    public int account_number { get; set; }

    [Display(Name = "Название объекта")]
    [Required(ErrorMessage = "Поле 'Название объекта' обязательно для заполнения.")]
    public string full_name { get; set; }

    [Display(Name = "Телефон")]
    [Required(ErrorMessage = "Поле 'Телефон' обязательно для заполнения.")]
    [RegularExpression(@"^\d{10}$", ErrorMessage = "Телефон должен состоять из 10 цифр.")]
    public int phone { get; set; }

    [Display(Name = "Вид услуги")]
    [Required(ErrorMessage = "Поле 'Вид услуги' обязательно для заполнения.")]
    public string service_type { get; set; }

    public int? ContractsId { get; set; }
    public Contracts contracts { get; set; }

    public virtual ICollection<Employees> Employeess { get; set; }

    public Secured_Objects()
    {
        Employeess = new List<Employees>();
    }
}

} Как можно заметить я сделал внешние ключи. Далее сделал миграцию с помощью команды Add-Migration, но при попытке сделать обновление базы данных вылетает следующая ошибка: PM> Add-Migration "MigrateF" Build started... Build succeeded. Microsoft.EntityFrameworkCore.Infrastructure[10403] Entity Framework Core 6.0.26 initialized 'EmployeesDBContext' using provider 'Microsoft.EntityFrameworkCore.SqlServer:6.0.26' with options: None An operation was scaffolded that may result in the loss of data. Please review the migration for accuracy. To undo this action, use Remove-Migration. PM> Update-Database Build started... Build succeeded. Microsoft.EntityFrameworkCore.Infrastructure[10403] Entity Framework Core 6.0.26 initialized 'EmployeesDBContext' using provider 'Microsoft.EntityFrameworkCore.SqlServer:6.0.26' with options: None Microsoft.EntityFrameworkCore.Database.Command[20101] Executed DbCommand (24ms) [Parameters=[], CommandType='Text', CommandTimeout='30'] SELECT 1 Microsoft.EntityFrameworkCore.Database.Command[20101] Executed DbCommand (27ms) [Parameters=[], CommandType='Text', CommandTimeout='30'] SELECT OBJECT_ID(N'[__EFMigrationsHistory]'); Microsoft.EntityFrameworkCore.Database.Command[20101] Executed DbCommand (2ms) [Parameters=[], CommandType='Text', CommandTimeout='30'] SELECT 1 Microsoft.EntityFrameworkCore.Database.Command[20101] Executed DbCommand (0ms) [Parameters=[], CommandType='Text', CommandTimeout='30'] SELECT OBJECT_ID(N'[__EFMigrationsHistory]'); Microsoft.EntityFrameworkCore.Database.Command[20101] Executed DbCommand (14ms) [Parameters=[], CommandType='Text', CommandTimeout='30'] SELECT [MigrationId], [ProductVersion] FROM [__EFMigrationsHistory] ORDER BY [MigrationId]; Microsoft.EntityFrameworkCore.Migrations[20402] Applying migration '20240320112849_ForeigKeys'. Applying migration '20240320112849_ForeigKeys'. fail: Microsoft.EntityFrameworkCore.Database.Command[20102] Failed executing DbCommand (5ms) [Parameters=[], CommandType='Text', CommandTimeout='30'] DROP TABLE [EmployeesSecured_Objects]; Failed executing DbCommand (5ms) [Parameters=[], CommandType='Text', CommandTimeout='30'] DROP TABLE [EmployeesSecured_Objects]; Microsoft.Data.SqlClient.SqlException (0x80131904): Cannot drop the table 'EmployeesSecured_Objects', because it does not exist or you do not have permission. at Microsoft.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action1 wrapCloseInAction) at Microsoft.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection, Action1 wrapCloseInAction) at Microsoft.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose) at Microsoft.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady) at Microsoft.Data.SqlClient.SqlCommand.RunExecuteNonQueryTds(String methodName, Boolean isAsync, Int32 timeout, Boolean asyncWrite) at Microsoft.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(TaskCompletionSource1 completion, Boolean sendToPipe, Int32 timeout, Boolean& usedCache, Boolean asyncWrite, Boolean inRetry, String methodName) at Microsoft.Data.SqlClient.SqlCommand.ExecuteNonQuery() at Microsoft.EntityFrameworkCore.Storage.RelationalCommand.ExecuteNonQuery(RelationalCommandParameterObject parameterObject) 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 connectionString, String contextType) at Microsoft.EntityFrameworkCore.Design.OperationExecutor.UpdateDatabaseImpl(String targetMigration, String connectionString, String contextType) at Microsoft.EntityFrameworkCore.Design.OperationExecutor.UpdateDatabase.<>c__DisplayClass0_0.<.ctor>b__0() at Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase.Execute(Action action) ClientConnectionId:f958bdde-64d4-4eee-9a05-d22663a36de2 Error Number:3701,State:5,Class:11 Cannot drop the table 'EmployeesSecured_Objects', because it does not exist or you do not have permission.
Подскажите пожалуйста, где я мог допустить ошибку, и как ее исправить.


Ответы (0 шт):