Relation dbo.MyTable not found while schema and table do exist

心已入冬 提交于 2019-12-13 04:50:34

问题


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:

  1. Included the packages Npsql and Npsql.EntityFramework via NuGet.
  2. 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 the configSections element in Web.Config.
  3. 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 the DbProviderFactories element of system.data in the Web.config.
  4. 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.
  5. Created a schema named dbo, a database named ZkTestDatabase, a user named test, and a table named dbo.Crops to 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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!