Robert Keith
Robert Keith

Reputation: 104

“Unable to find a table” on Database First Scaffold-DbContext

For some reason I'm getting this error. Below are the specs and then what I did.

Visual Studio 2017 v15.6.2

SQL Server 2008 v10.50.4

I opened the package manager console and added the following packages...

Install-Package Microsoft.EntityFrameworkCore.SqlServer

Install-Package Microsoft.EntityFrameworkCore.Tools

and then I ran

Scaffold-DbContext "Server=ph2srv76;Database=AVDRS;Integrated Security=True;Trusted_Connection=True;" -Provider Microsoft.EntityFrameworkCore.SqlServer -OutputDir Models -force

but during the build I get the following errors...

enter image description here

Upvotes: 4

Views: 6499

Answers (4)

martial
martial

Reputation: 3893

In my case, I used -table option. I got the same error when I do this:

-Tables "REPORT, REPORT_TYPE, SAVED_REPORT"

The correct way is this:

-Tables "REPORT", "REPORT_TYPE", "SAVED_REPORT"

Upvotes: 0

user847335
user847335

Reputation: 155

I hate to post the obvious, but in my case (same error) I was targeting specific tables to model (with -t option) and didn't realize that the table names are case sensitive. Doh!

Upvotes: 9

GrahamJ
GrahamJ

Reputation: 528

In case anyone else gets this I solved it by checking and fixing the following:

  1. Make sure that the user id you are using in the scaffold-dbcontext actually has permissions on the tables you want to scaffold. If not the scaffold cannot find them.
  2. Make sure the tables have primary keys or EF cannot scaffold them. Makes sense if you think about it.

After the above the scaffold worked for me!

Upvotes: 2

ErikEJ
ErikEJ

Reputation: 41809

Those are just warnings (yellow), not errors(red) - you can safely ignore them

Upvotes: 2

Related Questions