I add first migration and it is done without problem
The problem I get when I try to update-database and I get following:
PM> add-migration initial
Build started...
Build succeeded.
To undo this action, use Remove-Migration.
PM> update-database
Build started...
Build succeeded.
System.NullReferenceException: Object reference not set to an instance of an object.
at Microsoft.EntityFrameworkCore.Migrations.MigrationsSqlGenerator.GetColumnType(String schema, String table, String name, ColumnOperation operation, IModel model)
at Npgsql.EntityFrameworkCore.PostgreSQL.Migrations.NpgsqlMigrationsSqlGenerator.ColumnDefinition(String schema, String table, String name, ColumnOperation operation, IModel model, MigrationCommandListBuilder builder)
at Microsoft.EntityFrameworkCore.Migrations.MigrationsSqlGenerator.ColumnDefinition(AddColumnOperation operation, IModel model, MigrationCommandListBuilder builder)
at Microsoft.EntityFrameworkCore.Migrations.MigrationsSqlGenerator.CreateTableColumns(CreateTableOperation operation, IModel model, MigrationCommandListBuilder builder)
at Npgsql.EntityFrameworkCore.PostgreSQL.Migrations.NpgsqlMigrationsSqlGenerator.Generate(CreateTableOperation operation, IModel model, MigrationCommandListBuilder builder, Boolean terminate)
at Microsoft.EntityFrameworkCore.Migrations.MigrationsSqlGenerator.<>c.<.cctor>b__71_11(MigrationsSqlGenerator g, MigrationOperation o, IModel m, MigrationCommandListBuilder b)
at Microsoft.EntityFrameworkCore.Migrations.MigrationsSqlGenerator.Generate(MigrationOperation operation, IModel model, MigrationCommandListBuilder builder)
at Npgsql.EntityFrameworkCore.PostgreSQL.Migrations.NpgsqlMigrationsSqlGenerator.Generate(MigrationOperation operation, IModel model, MigrationCommandListBuilder builder)
at Microsoft.EntityFrameworkCore.Migrations.MigrationsSqlGenerator.Generate(IReadOnlyList`1 operations, IModel model)
at Microsoft.EntityFrameworkCore.Migrations.Internal.Migrator.GenerateUpSql(Migration migration)
at Microsoft.EntityFrameworkCore.Migrations.Internal.Migrator.<>c__DisplayClass15_2.<GetMigrationCommandLists>b__2()
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.UpdateDatabaseImpl(String targetMigration, String contextType)
at Microsoft.EntityFrameworkCore.Design.OperationExecutor.UpdateDatabase.<>c__DisplayClass0_0.<.ctor>b__0()
at Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase.Execute(Action action)
Object reference not set to an instance of an object.
The problem was that I inserted on one class a type of data that is non compatible with postgreSql like List<string> and List<EmailMessageFlag> that is a list of Enum.
I fixed with creating a support class with each of that kind of properties.
So now I can Migrate (and Update the Database) but now
I have a new error on Remove-Migration:
PM> add-migration Initial
Build started...
Build succeeded.
To undo this action, use Remove-Migration.
PM> remove-migration
Build started...
Build succeeded.
System.NullReferenceException: Object reference not set to an instance of an object.
at Microsoft.EntityFrameworkCore.Migrations.Internal.MigrationsModelDiffer.Initialize(ColumnOperation columnOperation, IProperty property, CoreTypeMapping typeMapping, Boolean isNullable, IEnumerable`1 migrationsAnnotations, Boolean inline)
at Microsoft.EntityFrameworkCore.Migrations.Internal.MigrationsModelDiffer.Add(IProperty target, DiffContext diffContext, Boolean inline)+MoveNext()
at System.Linq.Enumerable.SelectManySingleSelectorIterator`2.MoveNext()
at System.Linq.Enumerable.CastIterator[TResult](IEnumerable source)+MoveNext()
at System.Collections.Generic.List`1.InsertRange(Int32 index, IEnumerable`1 collection)
at Microsoft.EntityFrameworkCore.Migrations.Internal.MigrationsModelDiffer.Add(ITable target, DiffContext diffContext)+MoveNext()
at Microsoft.EntityFrameworkCore.Migrations.Internal.MigrationsModelDiffer.DiffCollection[T](IEnumerable`1 sources, IEnumerable`1 targets, DiffContext diffContext, Func`4 diff, Func`3 add, Func`3 remove, Func`4[] predicates)+MoveNext()
at System.Linq.Enumerable.ConcatIterator`1.MoveNext()
at System.Linq.Enumerable.Any[TSource](IEnumerable`1 source)
at Microsoft.EntityFrameworkCore.Migrations.Internal.MigrationsModelDiffer.HasDifferences(IModel source, IModel target)
at Microsoft.EntityFrameworkCore.Migrations.Design.MigrationsScaffolder.RemoveMigration(String projectDir, String rootNamespace, Boolean force, String language)
at Microsoft.EntityFrameworkCore.Design.Internal.MigrationsOperations.RemoveMigration(String contextType, Boolean force)
at Microsoft.EntityFrameworkCore.Design.OperationExecutor.RemoveMigrationImpl(String contextType, Boolean force)
at Microsoft.EntityFrameworkCore.Design.OperationExecutor.RemoveMigration.<>c__DisplayClass0_0.<.ctor>b__0()
at Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase.<>c__DisplayClass3_0`1.<Execute>b__0()
at Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase.Execute(Action action)
Object reference not set to an instance of an object.
Could you share your model design and the DbContext?
Best Regards,
Rena
.NET forums are moving to a new home on Microsoft Q&A, we encourage you to go to Microsoft Q&A for .NET for posting new questions and get involved today.
using FidaBlazor.Shared.Email;
using FidaBlazor.Shared.Enums;
using FidaBlazor.Shared.Models.Account.Login;
using FidaBlazor.Shared.Models.Menus;
using FidaBlazorUI_Share.Models.Language;
using Microsoft.AspNetCore.Identity;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
namespace FidaBlazor.Shared.Models.Account
{
public class User : IdentityUser<int>
{
[MaxLength(64)]
public string FirstName { get; set; }
[MaxLength(64)]
public string LastName { get; set; }
public UserProfile Profile { get; set; }
public DateTime BirthDate { get; set; }
public string PlaceOfBirth { get; set; }
public Gender Gender { get; set; }
public string Thumbnail { get; set; }
public string PhotoUrl { get; set; }
public bool IsDisabled { get; set; }
public string ImapPassword { get; set; }
[Required]
public LanguageCode Language { get; set; }
public AppDynamicNavMenu AppDynamicNavMenu { get; set; }
public List<UserMailAddress> SecondaryEMailAddresses { get; set; }
public List<UserAddress> Adresses { get; set; }
public List<PhoneNumber> PhoneNumbers { get; set; }
public List<UserIdentityNumber> IdentityNumbers { get; set; }
public ICollection<UserRole> UserRoles { get; set; }
public List<OldPassword> oldPasswords { get; set; }
public List<EmailMessage> EmailMessages { get; set; }
public List<EmailTemplate> EmailTemplates { get; set; }
}
}
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
namespace FidaBlazorUI_Share.Models.Language
{
public class BaseLangCode
{
[Key]
public int Id { get; set; }
[Required]
public string KeyText { get; set; }
public List<LangTranslation> LangTranslations { get; set; }
}
}
using System.Collections.Generic;
namespace FidaBlazorUI_Share.Models.Language
{
public class LangTranslation
{
public int Id { get; set; }
public string Translation { get; set; }
public BaseLangCode BaseLang { get; set; }
public LanguageCode LangCode { get; set; }
public List<LangTransPage> LangTransPages { get; set; }
}
}
using System;
using System.Collections.Generic;
using System.Text;
namespace FidaBlazorUI_Share.Models.Language
{
public class LangTransPage
{
public int langTranslationId { get; set; }
public int PageId { get; set; }
public LangTranslation LangTranslation { get; set; }
public Page Page { get; set; }
}
}
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
namespace FidaBlazorUI_Share.Models.Language
{
public class LanguageCode
{
[Key]
public int Id { get; set; }
public string Code { get; set; }
public string Description { get; set; }
public List<LangTranslation> LangTranslations { get; set; }
}
}
using FidaBlazorUI_Share.Models.Language;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Text;
namespace FidaBlazorUI_Share.Models
{
public class Page
{
[Key]
public int Id { get; set; }
[Required]
public string Name { get; set; }
public string Url { get; set; }
public List<LangTransPage> LangTransPages { get; set; }
}
}
using FidaBlazor.Shared.Models.Account;
using System.Collections.Generic;
namespace FidaBlazor.Shared.Models.Menus
{
public class AppDynamicNavMenu : MenuBase
{
public bool Multi { get; set; }
public User ApplicationUser { get; set; }
public List<NavMenuItem> MenuItems { get; set; }
public List<SubMenu> SubMenus { get; set; }
}
}
using FidaBlazor.Shared.Enums;
using FidaBlazor.Shared.Models.Account;
using MailKit;
using MimeKit;
using MimeKit.Utils;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.IO;
using System.Linq;
using System.Text;
namespace FidaBlazor.Shared.Email
{
public class EmailMessage
{
public EmailMessage()
{
MessageId = MimeUtils.GenerateMessageId();
ToAddresses = new List<EmailAddress>();
FromAddresses = new List<EmailAddress>();
CcAddresses = new List<EmailAddress>();
BccAddresses = new List<EmailAddress>();
Attachments = new List<EmailAttachment>();
Headers = new List<EmailHeader>();
References = new List<EmailMessageId>();
ReplyTo = new List<EmailAddress>();
MessageFlags = new List<EmailMessageFlag>();
}
public EmailMessage(MimeMessage message)
{
MessageId = message.MessageId;
ToAddresses = new List<EmailAddress>();
FromAddresses = new List<EmailAddress>();
CcAddresses = new List<EmailAddress>();
BccAddresses = new List<EmailAddress>();
ReplyTo = new List<EmailAddress>();
Attachments = new List<EmailAttachment>();
Headers = new List<EmailHeader>();
References = new List<EmailMessageId>();
MessageFlags = new List<EmailMessageFlag>();
ToAddresses.AddRange(message.To.Select(x => (MailboxAddress)x).Select(x => new EmailAddress(x.Name, x.Address)));
FromAddresses.AddRange(message.From.Select(x => (MailboxAddress)x).Select(x => new EmailAddress(x.Name, x.Address)));
CcAddresses.AddRange(message.Cc.Select(x => (MailboxAddress)x).Select(x => new EmailAddress(x.Name, x.Address)));
BccAddresses.AddRange(message.Bcc.Select(x => (MailboxAddress)x).Select(x => new EmailAddress(x.Name, x.Address)));
Body = !string.IsNullOrEmpty(message.HtmlBody) ? message.HtmlBody : message.TextBody;
Subject = message.Subject;
foreach (var attachment in message.Attachments)
{
byte[] attachmentByteArray;
using var ms = new MemoryStream();
{
string fileName;
ContentType contentType = null;
if (attachment is MessagePart part1)
{
fileName = attachment.ContentDisposition?.FileName;
var rfc822 = part1;
if (string.IsNullOrEmpty(fileName))
fileName = "attached-message.eml";
rfc822.Message.WriteTo(ms);
attachmentByteArray = ms.ToArray();
}
else
{
var part = (MimePart)attachment;
fileName = part.FileName;
contentType = part.ContentType;
part.Content.DecodeTo(ms);
attachmentByteArray = ms.ToArray();
}
EmailAttachment mailAttachment = new EmailAttachment(fileName, attachmentByteArray, contentType);
Attachments.Add(mailAttachment);
}
}
foreach (var header in message.Headers)
{
Headers.Add(new EmailHeader(header));
}
foreach (var header in Headers)
{
if (header.Field.ToLower().Contains("Disposition-Notification-To"))
{
NeedReadReceipt = true;
}
if (header.Field.ToLower().Contains("Return-Receipt-To"))
{
NeedReadReceipt = true;
}
}
foreach (var intAdd in message.ReplyTo)
{
ReplyTo.Add(new EmailAddress(intAdd.Name, intAdd.Name));
}
Date = message.Date;
Importance = message.Importance;
Priority = message.Priority;
foreach (var messId in message.References)
{
References.Add(new EmailMessageId(messId));
}
InReplyTo = message.InReplyTo;
if (message.Sender != null)
Sender = new EmailAddress(message.Sender.Name, message.Sender.Address);
}
public List<EmailAddress> ToAddresses { get; set; }
public List<EmailAddress> FromAddresses { get; set; }
public List<EmailAddress> BccAddresses { get; set; }
public List<EmailAddress> CcAddresses { get; set; }
public List<EmailAttachment> Attachments { get; set; }
public List<EmailHeader> Headers { get; set; }
public List<EmailMessageId> References { get; set; }
public List<EmailAddress> ReplyTo { get; set; }
public List<EmailMessageFlag> MessageFlags { get; set; }
[Key]
public int Id { get; set; }
public string MessageId { get; set; }
public uint Uid { get; set; }
public DateTimeOffset Date { get; set; }
public MessageImportance Importance { get; set; }
public MessagePriority Priority { get; set; }
public string Subject { get; set; }
public string Body { get; set; }
public bool IsHtml { get; set; } = true;
public bool NeedReadReceipt { get; set; }
public bool NeedDeliveredReceipt { get; set; }
public string InReplyTo { get; set; }
public EmailAddress Sender { get; set; }
public EmailMessageDirection MessageDirection { get; set; }
public User User { get; set; }
}
}
using FidaBlazor.Shared.Models.Account;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Text;
namespace FidaBlazor.Shared.Email
{
public class EmailTemplate
{
[Key]
public int Id { get; set; }
public string ClassDataSource { get; set; }
public string TemplateName { get; set; }
public string Subject { get; set; }
public string Body { get; set; }
public bool NeedReadReceipt { get; set; }
public bool NeedDeliveredReceipt { get; set; }
public bool Shared { get; set; }
public User User { get; set; }
public List<EmailAttachment> Attachments { get; set; }
}
}
using System.ComponentModel.DataAnnotations;
namespace FidaBlazor.Shared.Models.Account.Login
{
public class OldPassword
{
[Key]
public int id { get; set; }
public string oldPasswordHash { get; set; }
}
}
using FidaBlazor.Shared.Enums;
using System.ComponentModel.DataAnnotations;
namespace FidaBlazor.Shared.Models.Account
{
public class PhoneNumber
{
public PhoneNumber()
{
}
public PhoneNumber(PhoneNumber newPhoneNumber)
{
CountryDialCode = newPhoneNumber.CountryDialCode;
Number = newPhoneNumber.Number;
NumberType = newPhoneNumber.NumberType;
Notes = newPhoneNumber.Notes;
}
[Key]
public int Id { get; set; }
[Required]
public string CountryDialCode { get; set; }
[Required]
public string Number { get; set; }
public PhoneType NumberType { get; set; }
public string Notes { get; set; }
public User User { get; set; }
}
}
using FidaBlazor.Shared.CustomValidators;
using FidaBlazor.Shared.Enums;
using System.ComponentModel.DataAnnotations;
namespace FidaBlazor.Shared.Models.Account
{
public class UserAddress
{
public UserAddress()
{
}
public UserAddress(UserAddress newUserAddres)
{
NameId = newUserAddres.NameId;
Street = newUserAddres.Street;
Number = newUserAddres.Number;
Flat = newUserAddres.Flat;
Staircase = newUserAddres.Staircase;
City = newUserAddres.City;
PostalCode = newUserAddres.PostalCode;
County = newUserAddres.County;
Country = newUserAddres.Country;
State = newUserAddres.State;
AddressType = newUserAddres.AddressType;
}
[Key]
public int Id { get; set; }
[Required]
public string NameId { get; set; }
[Required]
public string Street { get; set; }
[Required]
public string Number { get; set; }
public string Flat { get; set; }
public string Staircase { get; set; }
[Required]
public string City { get; set; }
[Required]
public string PostalCode { get; set; }
[Required]
public string County { get; set; }
[Required]
public CountryEnum Country { get; set; }
public string State { get; set; }
[AddressTypeNone(ErrorMessage = "Address Type None Not Allowed")]
public AddressType AddressType { get; set; }
public User User { get; set; }
}
}
using FidaBlazor.Shared.Enums;
using System;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
namespace FidaBlazor.Shared.Models.Account
{
public class UserIdentityNumber : INotifyPropertyChanged
{
public UserIdentityNumber()
{
}
public UserIdentityNumber(UserIdentityNumber newIdentityNumber)
{
IdNumber = newIdentityNumber.IdNumber;
IdType = newIdentityNumber.IdType;
DocumentCopyUrl = newIdentityNumber.DocumentCopyUrl;
DocumentThumbnail = newIdentityNumber.DocumentThumbnail;
IssuingDate = newIdentityNumber.IssuingDate;
ExpiringDate = newIdentityNumber.ExpiringDate;
DocumentIssuer = newIdentityNumber.DocumentIssuer;
IssuingPlace = newIdentityNumber.IssuingPlace;
}
[Key]
public int Id { get; set; }
[Required]
public string IdNumber { get; set; }
[Required]
public IdNumberType IdType { get; set; }
private string documentCopyUrl;
public string DocumentCopyUrl
{
get => documentCopyUrl;
set
{
documentCopyUrl = value;
OnPropertyChanged("DocumentCopyUrl");
}
}
public string DocumentThumbnail { get; set; }
public DateTime IssuingDate { get; set; }
public DateTime ExpiringDate { get; set; }
public string DocumentIssuer { get; set; }
public string IssuingPlace { get; set; }
public User User { get; set; }
public event PropertyChangedEventHandler PropertyChanged;
protected void OnPropertyChanged(string propertyName)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
}
}
using FidaBlazor.Shared.Enums;
using System.ComponentModel.DataAnnotations;
namespace FidaBlazor.Shared.Models.Account
{
public class UserMailAddress
{
private string _name;
[Key]
public int Id { get; set; }
public string Name
{
get
{
if (string.IsNullOrEmpty(_name))
{
return Address;
}
return _name;
}
set
{
_name = value;
}
}
[Required]
[EmailAddress]
[DataType(DataType.EmailAddress)]
public string Address { get; set; }
public EmailType MailType { get; set; }
public User User { get; set; }
public UserMailAddress(string address, EmailType mailType, string name = "")
{
_name = name;
Address = address;
MailType = mailType;
}
public UserMailAddress()
{
}
}
}
using System;
using System.ComponentModel.DataAnnotations;
namespace FidaBlazor.Shared.Models.Account
{
public class UserProfile
{
[Key]
public long Id { get; set; }
public int UserId { get; set; }
public User ApplicationUser { get; set; }
public string LastPageVisited { get; set; } = "/";
public bool IsNavOpen { get; set; } = true;
public bool IsNavMinified { get; set; } = false;
public int Count { get; set; } = 0;
public DateTime LastUpdatedDate { get; set; } = DateTime.MinValue;
}
}
namespace FidaBlazorUI_Share.Models.Language
{
public class LangTransPage
{
public int langTranslationId { get; set; }
public int PageId { get; set; }
public LangTranslation LangTranslation { get; set; }
public Page Page { get; set; }
}
}
using System;
using System.Collections.Generic;
using System.Text;
namespace FidaBlazor.Shared.Email
{
public class EmailAddress
{
private string _name;
public EmailAddress(string name, string address)
{
_name = name;
Address = address;
}
public int Id { get; set; }
public string Name
{
get
{
if (string.IsNullOrEmpty(_name))
{
return Address;
}
return _name;
}
set
{
_name = value;
}
}
public string Address { get; set; }
public EmailMessage ToEmailMessage { get; set; }
public EmailMessage FromEmailMessage { get; set; }
public EmailMessage CcEmailMessage { get; set; }
public EmailMessage BccEmailMessage { get; set; }
public EmailMessage ReplyEmailMessage { get; set; }
public EmailMessage SenderEmailMessage { get; set; }
}
}
using MimeKit;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Text;
namespace FidaBlazor.Shared.Email
{
public class EmailHeader
{
public EmailHeader()
{
}
public EmailHeader(Header header)
{
RawField = header.RawField;
HeaderId = header.Id;
Field = header.Field;
Offset = header.Offset;
RawValue = header.RawValue;
Value = header.Value;
}
[Key]
public int Id { get; set; }
public byte[] RawField { get; }
public HeaderId HeaderId { get; }
public string Field { get; }
public long? Offset { get; }
public byte[] RawValue { get; }
public string Value { get; set; }
public EmailMessage EmailMessage { get; set; }
}
}
using FidaBlazor.Shared.Enums;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Text;
namespace FidaBlazor.Shared.Email
{
public class EmailMessageFlag
{
[Key]
public int Id { get; set; }
public EmailMessageFlagEnum MessageFlag { get; set; }
public EmailMessage EmailMessage { get; set; }
}
}
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Text;
namespace FidaBlazor.Shared.Email
{
public class EmailMessageId
{
public EmailMessageId(string messageId)
{
MessageId = messageId;
}
[Key]
public string Id { get; set; }
public string MessageId { get; set; }
public EmailMessage EmailMessage { get; set; }
}
}
using MimeKit;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.IO;
using System.Text;
using System.Threading.Tasks;
namespace FidaBlazor.Shared.Email
{
public class EmailAttachment
{
private EmailAttachment()
{
}
public EmailAttachment(string fileName, string fileNameUrl)
{
FileName = fileName;
FileNameUrl = fileNameUrl;
FileFullPath = fileNameUrl + "/" + fileName;
}
public EmailAttachment(string fileName, byte[] fileDataBytes)
{
FileName = fileName;
FileDataBytes = fileDataBytes;
}
public EmailAttachment(string fileName, ContentType contentType)
{
FileName = fileName;
ContentType = contentType;
}
public EmailAttachment(string fileName, byte[] fileDataBytes, ContentType contentType)
{
FileName = fileName;
FileDataBytes = fileDataBytes;
ContentType = contentType;
}
[Key]
public int Id { get; set; }
public string FileName { get; internal set; }
public string FileNameUrl { get; internal set; }
public string FileFullPath { get; internal set; }
public string FileUrl { get; internal set; }
public ContentType ContentType { get; }
public byte[] FileDataBytes { get; internal set; }
public EmailTemplate Template { get; set; }
public EmailMessage EmailMessage { get; set; }
}
}
namespace FidaBlazor.Shared.Models.Menus
{
public class NavMenuItem : MenuBase
{
public string Href { get; set; }
public bool Disabled { get; set; }
public bool AllowSection { get; set; }
public string Content { get; set; }
public string Icon { get; set; }
public SubMenuHeader SubMenuHeader { get; set; }
}
}
namespace FidaBlazor.Shared.Models.Menus
{
public class SubMenu : MenuBase
{
public bool Selected { get; set; }
public bool Expanded { get; set; }
public SubMenuHeader SubMenuHeader { get; set; }
public SubMenuList SubMenuList { get; set; }
}
}
namespace FidaBlazor.Shared.Models.Menus
{
public class SubMenuHeader : MenuBase
{
public string Content { get; set; }
public NavMenuItem NavMenuItem { get; set; }
public SubMenu SubMenu { get; set; }
}
}
using System.Collections.Generic;
namespace FidaBlazor.Shared.Models.Menus
{
public class SubMenuList : MenuBase
{
public SubMenu SubMenu { get; set; }
public List<NavMenuItem> Items { get; set; }
public List<SubMenu> SubMenus { get; set; }
}
}
Member
2 Points
7 Posts
Migration Issue with Npgsql.EntityFrameworkCore.PostgreSQL
Apr 22, 2020 03:00 PM|PiercarloBI|LINK
Hi,
I have following problem when I try to add a migration:
Premises:
I´m using Net.Core 5.0.0 preview 2
Database PostgreSql last version
Entity framework tools 5.0.0 preview 2
Npgsql.EntityFrameworkCore.PostgreSQL 5.0.0 preview 2
The error:
I add first migration and it is done without problem
The problem I get when I try to update-database and I get following:
the migration is this:
some tip ?
Thank you in advance
Member
2 Points
7 Posts
Re: Migration Issue with Npgsql.EntityFrameworkCore.PostgreSQL
Apr 22, 2020 03:46 PM|PiercarloBI|LINK
Hi,
I answer for my self because I found the error:
The problem was that I inserted on one class a type of data that is non compatible with postgreSql like List<string> and List<EmailMessageFlag> that is a list of Enum.
I fixed with creating a support class with each of that kind of properties.
So now I can Migrate (and Update the Database) but now
I have a new error on Remove-Migration:
Tanks for help
Contributor
2690 Points
874 Posts
Re: Migration Issue with Npgsql.EntityFrameworkCore.PostgreSQL
Apr 23, 2020 09:43 AM|Rena Ni|LINK
Hi PiercarloBI,
Could you share your model design and the DbContext?
Best Regards,
Rena
Member
2 Points
7 Posts
Re: Migration Issue with Npgsql.EntityFrameworkCore.PostgreSQL
Apr 23, 2020 12:19 PM|PiercarloBI|LINK
Hello Rena,
Here My DbContext:
The Initial Migration:
The Last Migration:
The Models:
Ok I think that´s all
Bye