关系dbo.MyTable在模式和表确实存在时找不到 [英] Relation dbo.MyTable not found while schema and table do exist
问题描述
- 包含包
Npsql
和Npsql.EntityFramework
通过NuGet。 - 添加了
< section name =entityFrameworktype =System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection,EntityFramework,Version = 6.1.1 ,Culture = neutral,PublicKeyToken = b77a5c561934e089requirePermission =false/>
到Web中的
。configSections
元素。配置 - 添加
< remove invariant =Npgsql>< / remove>
< add name =Npgsqlinvariant =Npgsqldescription =。Postgresql Server的Net Framework数据提供者type =Npgsql.NpgsqlFactory,Npgsql,Version = 2.2.2,Culture = neutral /
DbProviderFactories
元素system.data
在Web.config
。 - 添加以下连接字符串
< add name =ZkTestDatabaseConnectionconnectionString =Server = localhost; Port = 5432; Database = ZkTestDatabase; User Id = test; Password = password; CommandTimeout = 20;创建了一个名为
dbo
的实例框架 - >,名为
ZkTestDatabase
的数据库,名为test
的用户,以及名为dbo的表。作物
到PostgreSQL中的此数据库(请参阅此脚本)。 li>
当我用用户 test
登录并执行 select * from dbo.Crops;
(我也尝试通过创建一个表创建表dbo.Crops;
而不是创建表dbo.Crops;
。我得到正确的输出。
现在,当我去一个模型作物
(根据这个映射到表格的约定作物
)我收到消息:
Npgsql.NpgsqlException
错误:42P01:关系dbo.Crops不存在
描述:HTTP 500.Error处理请求。
详细说明:不eb例外。异常来源(应用程序或对象的名称):Npgsql。
异常堆栈跟踪:
在Npgsql.NpgsqlState +< ProcessBackendResponses> d__0.MoveNext()[$ 0x00000]
< filename unknown>:0在Npgsql.ForwardsOnlyDataReader.GetNextResponseObject
(Boolean cleanup)[0x00000] in< filename unknown>:0
我很高兴应用程序了解到它需要连接到数据库,并找到一个关系 dbo.Crops
。我有点伤心,但是无法找到关系。
*编辑:执行 select from pg_tables;
返回以下内容:
schemaname | tablename | tableowner |表空间| hasindexes | hasrules | hastriggers
-------------------- + ------------------------ - + ------------ + ------------ + ------------ + --------- - + -------------
public | dbo.Crops | zktest | | t | f | f
我不知道为什么会出现这个错误,我已经用尽了我有限的理解中的所有功能。我希望别人看到一个可能的解决方案。
从pg_tables执行select *,看看是什么。那应该让你在正确的路上。
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
Npsql
andNpsql.EntityFramework
via 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 theconfigSections
element 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 theDbProviderFactories
element ofsystem.data
in 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.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.
Perform a select * from pg_tables and see what comes back. That should get you on the right course.
这篇关于关系dbo.MyTable在模式和表确实存在时找不到的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!