Reputation: 1108
So I'm using Entity Framework Code First to create tables in an existing remote SQL Server database and when I do:
Enable-Migrations
Add-Migration Inital
Update-Database
No tables are created whatsoever. This is my DbContext:
using Microsoft.AspNet.Identity.EntityFramework;
using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Linq;
using TrabalhoDefinitivo.Models;
using TrabalhoDefinitivo.ViewModels;
namespace TrabalhoDefinitivo.DAL
{
public class ApplicationDbContext : IdentityDbContext<ApplicationUser>
{
public ApplicationDbContext()
: base("DefaultConnection")
{
}
public DbSet<Sale> Sales { get; set; }
public DbSet<Album> Albums { get; set; }
public DbSet<AlbumType> AlbumTypes { get; set; }
public DbSet<SaleAlbum> SaleAlbums { get; set; }
}
}
I tried adding a new connection string manuall in Web.config with this:
<add name="ApplicationServices"
connectionString="Data Source=gandalf.dei.isep.ipp.pt\sqlexpress;
Initial Catalog=xxxx;
User ID=xxxx;
Password=xxxx"
providerName="System.Data.SqlClient" />
After that I added a new connection in server explorer, testing it with success and repeated step one. No tables again.
What am I doing wrong?
Upvotes: 4
Views: 3859
Reputation: 22516
Change ApplicationDbContext cnstructor to
public ApplicationDbContext()
: base("ApplicationServices")
{
}
That way you will use the Connection string from your Web.config
Upvotes: 5