I have created a DbContext
using EF Core 2.0 and already applied a lot of migrations in the development environment using Update-Database
in PM-Console.
The tables are created using the dbo
schema on my localDb as expected and as I know from EF6.
However, when i apply the Update-Database
command to my production database on a MSSQL Server, it creates a schema named Domain\Username
(my user from my machine). When I then run the server application with its designated domain account, it can not access the database. As a workaround I talked the IT infrastructure guys into allowing this account to execute software on my computer and applied the migritions by executing VisualStudio with this account. Then a schema for this special account is created and thereafter it can access the database fro the webserver application. It works since this special account is currently the only one that needs direct access to the database (besides myself). But this should ne be a permanent solution.
Does anyone know a solution for this? The database has been created in the exactly same manner as for previous EF6 projects.
Why are the per user schemas only used when applying the migrations to the production system and not on my development machine and how can I control the schema manually?
I tried modelBuilder.HasDefaultSchema("dbo");
but this does not work. Actually it seems to not having any effect at all.
The dbo schema is the default schema of every database. By default, users created with the CREATE USER Transact-SQL command have dbo as their default schema. The dbo schema is owned by the dbo user account.
Right-click anywhere on the design surface, and select Update Model from Database... In the Update Wizard, select the Refresh tab and select your table then click Finish button.
I had the same problem and believe it was caused by having my domain\user
listed under MyDatabase -> Security -> Users
. I fixed the issue by deleting my account from the users (right click -> delete) and the next time I ran update-database
it prefixed the tables correctly with 'dbo'.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With