问题
In our MVC 5.2 application on Mono 3.10 I am trying to set up a connection with a PostgreSQL database via Entity Framework 6.1.1. To do this I took the following steps:
- Included the packages
NpsqlandNpsql.EntityFrameworkvia NuGet. - Added the section
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.1.1, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />to theconfigSectionselement inWeb.Config. - Added
<remove invariant="Npgsql"></remove>and<add name="Npgsql" invariant="Npgsql" description=".Net Framework Data Provider for Postgresql Server" type="Npgsql.NpgsqlFactory, Npgsql, Version=2.2.2, Culture=neutral" />to theDbProviderFactorieselement ofsystem.datain theWeb.config. - Added the following connection string
<add name="ZkTestDatabaseConnection" connectionString="Server=localhost;Port=5432;Database=ZkTestDatabase;User Id=test;Password=password;CommandTimeout=20;" providerName="Npgsql" />that connects with Entity Framework context. - Created a schema named
dbo, a database namedZkTestDatabase, a user namedtest, and a table nameddbo.Cropsto this database in PostgreSQL (see this script).
When I am logged in with the user test and do select * from dbo.Crops; (I also tried making a table via create table "dbo.Crops"; instead of create table dbo.Crops;. I get the proper output.
Now, when I go a page with a model Crop (as per conventions this maps to a table Crops) I get the message:
Npgsql.NpgsqlException
ERROR: 42P01: relation "dbo.Crops" does not exist
Description: HTTP 500.Error processing request.
Details: Non-web exception. Exception origin (name of application or object): Npgsql.
Exception stack trace:
at Npgsql.NpgsqlState+<ProcessBackendResponses>d__0.MoveNext () [0x00000] in
<filename unknown>:0 at Npgsql.ForwardsOnlyDataReader.GetNextResponseObject
(Boolean cleanup) [0x00000] in <filename unknown>:0
I am very happy that the application understands that it needs to connect to a database and find a relation dbo.Crops. I am a bit sad however that the relation cannot be found.
*Edit: while performing select * from pg_tables; the following is returned:
schemaname | tablename | tableowner | tablespace | hasindexes | hasrules | hastriggers
--------------------+-------------------------+------------+------------+------------+----------+-------------
public | dbo.Crops | zktest | | t | f | f
I have no idea why this error pops up and I have exhausted all capabilities within my limited understanding. I hope someone else sees a possible solution.
回答1:
Perform a select * from pg_tables and see what comes back. That should get you on the right course.
来源:https://stackoverflow.com/questions/26941722/relation-dbo-mytable-not-found-while-schema-and-table-do-exist