EntityFramework6.Npgsql
EntityFramework6.Npgsql copied to clipboard
PostgresException: 42P01: relation "public.Authors" does not exist
Hi, I am using PostgreSQL database with EF6 code first approach, but I am getting the following exception
PostgresException: 42P01: relation "public.Authors" does not exist
Here is the model and context class.
public class BookStore : DbContext
{
public BookStore() : base(nameOrConnectionString: "Default")
{
}
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
modelBuilder.HasDefaultSchema("public");
}
public DbSet<Author> Authors { get; set; }
public DbSet<Book> Books { get; set; }
}
public class Author
{
public int AuthorId { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public DateTime BirthDate { get; set; }
public List<Book> Books { get; set; }
}
public class Book
{
public int BookId { get; set; }
public string Title { get; set; }
public Author Author { get; set; }
}
when inseting same data I am getting the exception.
using (var context = new BookStore())
{
var authors = new List<Author>
{
new Author
{
FirstName ="Carson",
LastName ="Alexander",
BirthDate = DateTime.Parse("1985-09-01"),
Books = new List<Book>()
{
new Book { Title = "Introduction to Machine Learning"},
new Book { Title = "Advanced Topics in Machine Learning"},
new Book { Title = "Introduction to Computing"}
}
}
};
context.Authors.AddRange(authors);
context.SaveChanges();
}
Have you solved this? I am facing the same issue right now.
Ok so this may be dumb but I was having this problem and it turned out that I had not updated the database since adding the migration dotnet ef database update