Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Entity framework code first migrations, sql user permissions?

What is the minimal permission needed on a sql server user/login for it to be able to run entity framework code first database migrations?

I naively would have thought that a user with the roles db_datareader, db_datawriter, Grant Alter on the Schema and Grant Create Table would be permissive enough.

like image 943
Mayoweezy Avatar asked Apr 23 '15 17:04

Mayoweezy


People also ask

Can we run SQL script using code First migrations?

This utility makes using Entity Framework Code-First much easier to manage running SQL scripts as part of the migrations or seed data. With this utility, we are running all the scripts as part of the migration without manually executing any of the scripts.

How do I code my first migration to an existing database?

Run the Add-Migration InitialCreate command in Package Manager Console. This creates a migration to create the existing schema. Comment out all code in the Up method of the newly created migration. This will allow us to 'apply' the migration to the local database without trying to recreate all the tables etc.

How do you use code first when an existing database schema?

To use code-first for an existing database, right click on your project in Visual Studio -> Add -> New Item.. Select ADO.NET Entity Data Model in the Add New Item dialog box and specify the model name (this will be a context class name) and click on Add.


1 Answers

On-Prem: SQL server with AD/sql login

you need the following permissions on the database.

[db_datareader]
[db_datawriter]
[db_ddladmin]

For full control over database use

[db_owner]

Azure Could: Azure SQL with ADD (Edit)

Please add [dbmanager] to master and user database.

like image 98
Hiten004 Avatar answered Sep 28 '22 05:09

Hiten004