Error in Exporting Created Models to Database in EDM


I already had a Users table on the database with the following columns and data types

  • Id - Int
  • username - varchar(MAX)
  • password - varchar(MAX)
  • RefreshToken - varchar(MAX)

Then I added several columns to it as shown below.

public class User

    public User()
        this.FollwedBies = new HashSet<FollwedBy>();
        this.UserFeedbacks = new HashSet<UserFeedback>();
        this.WishLIsts = new HashSet<WishLIst>();

    public int Id { get; set; }

    public string Email { get; set; }
    public string Name { get; set; }
    public DateTime BirthDate { get; set; }
    public string ProfilePictureUrl { get; set; }

    public string Username { get; set; }

    public string Password { get; set; }

    public byte IsDeleted { get; set; }

    public string RefreshToken { get; set; }

    public Nullable<System.DateTime> CreatedAt { get; set; }
    public Nullable<System.DateTime> ModifiedAt { get; set; }

    public virtual ICollection<FollwedBy> FollwedBies { get; set; }

    public virtual ICollection<UserFeedback> UserFeedbacks { get; set; }

    public virtual ICollection<WishLIst> WishLIsts { get; set; }

. once I give the Update-database it returns the following exception

Microsoft.Data.SqlClient.SqlException (0x80131904): Implicit conversion from data type varchar(max) to varbinary(max) is not allowed. Use the CONVERT function to run this query.

It also says that it failed to execute the following Dbcommand.

DECLARE @var2 sysname; SELECT @var2 = [d].[name] FROM [sys].[default_constraints] [d] INNER JOIN [sys].[columns] [c] ON [d].[parent_column_id] = [c].[column_id] AND [d].[parent_object_id] = [c].[object_id] WHERE ([d].[parent_object_id] = OBJECT_ID(N'[Users]') AND [c].[name] = N'Username'); IF @var2 IS NOT NULL EXEC(N'ALTER TABLE [Users] DROP CONSTRAINT [' + @var2 + '];'); ALTER TABLE [Users] ALTER COLUMN [Username] varbinary(max) NULL;

What would be the issue behind this error? Thank you very much in advance.


0 Answers

Nobody has answered this question yet.

User contributions licensed under CC BY-SA 3.0