Reputation: 47
I am currently trying to create a table with EF code-first in a SQL Server where I only have permissions to create tables in an existing database.
I cannot drop the entire database. I tried using migration update-table
to let EF create the table for me, but because a __MigrationHistory
table already exists (and is linked to different table), this didn't work.
Does anyone have a solution for my problem?
Upvotes: 1
Views: 561
Reputation: 2754
You need not to drop the whole database,
Add the class for the new Table, let's say your new Table is "person"
public class Person
{
public int Id { get; set; }
public string Name { get; set; }
}
and Add following line to DbContext
public DbSet<Person> Persons { get; set; }
Now you need to Add this table to the existing Database. The easiest way is Go to Nuget Package Manager Console (Tools-> Nuget Package Manager -> Package Manager Console) inside visual studio
type Add-Migration AddedPersonTable
This will create a new entry in the Migration Table
and then type Update-Database
This will Add the new persons table to the existing database
Read here for More information about Migrations.
Upvotes: 3