0

I'm using EF Core in a small test application and I'm trying to create the database in SQL Server 2014 Express. Initially I used Update-Database script to create it and I didn't have any issues but when I tried to do this at runtime with dbContext.Database.EnsureCreated(), it no longer worked. I have checked the credentials for the SQL user multiple times and I'm sure that both approaches use the same. If I use the Update-Database script first, then all the queries work successfully in runtime using the same credentials.

Any idea what I might be missing here?

Panayot Todorov
  • 397
  • 2
  • 11
  • Are you looking to Create the database and apply all migrations or you simply want to know if you have a database or not, because according to [this](https://stackoverflow.com/questions/38238043/how-and-where-to-call-database-ensurecreated-and-database-migrate) EnsureCreated() does not use migrations to create and update the database, on the contrary it simply creates the database and makes it compliant with the current schema. And if the database exists no action is taken. If you need to create the db and apply all migrations use context.Database.Migrate(); – Angel Venchev Oct 29 '18 at 13:31
  • I delete the database almost every time after the debug session ends, so it doesn't matter for me if it's created using migrations or not, as long as the schema is valid. Indeed I tried using the Migrate() method too but there wasn't any difference. – Panayot Todorov Oct 29 '18 at 13:57

0 Answers0