postgresql 错误:类型“日期时间”不存在
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/38826799/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
ERROR: type "datetime" does not exist
提问by Jose Ospina
I am trying to migrate my hibernate-based app from MySQL to Postgres, but there seems to be a problem with the date format
我正在尝试将基于休眠的应用程序从 MySQL 迁移到 Postgres,但日期格式似乎有问题
In my entity I have
在我的实体中,我有
@Entity
@Table( name = "APP_USERS" )
public class User {
@Id
@GeneratedValue(generator="increment")
@GenericGenerator(name="increment", strategy = "increment")
private int id;
private String username;
private String email;
private String password;
private String firstname;
private String lastname;
private Timestamp joindate;
...
but I get an error when creating the table
但是在创建表时出现错误
ERROR: type "datetime" does not exist
The sql from "showsql" is
来自“showsql”的 sql 是
Hibernate: create table APP_USERS (id integer not null, email varchar(255), firstname varchar(255), joindate datetime, lastname varchar(255), password varchar(255), username varchar(255), primary key (id))
I have postgresql-9.5.3-1 installed locally and I am using Hibernate version 5.0.10.Final
我在本地安装了 postgresql-9.5.3-1,我使用的是 Hibernate 版本 5.0.10.Final
Searching for that error on Google gives me very few results.
在谷歌上搜索那个错误给我的结果很少。
采纳答案by Mike Sherrill 'Cat Recall'
The top restult of a Google search for "postgresql datetime" would have taken you to PostgreSQL's documentation for date and time data types. It would be obvious from that page that your framework need to generate DDL that uses "timestamp" rather than "datetime".
Google 搜索“postgresql datetime”的最高结果会带您到 PostgreSQL 的日期和时间数据类型文档。从该页面可以明显看出,您的框架需要生成使用“时间戳”而不是“日期时间”的 DDL。
When any application framework generates the wrong data types for SQL DDL, the most likely problem is that it's configured to use the wrong database. In your case, it's likely still configured to use MySQL. Reconfigure for PostgreSQL.
当任何应用程序框架为 SQL DDL 生成错误的数据类型时,最可能的问题是它被配置为使用错误的数据库。在您的情况下,它可能仍配置为使用 MySQL。重新配置 PostgreSQL。
回答by d1ll1nger
PostgreSQL doesn't have datetime data type. For a combination of both you need "timestamp without time zone".
PostgreSQL 没有日期时间数据类型。对于两者的组合,您需要“没有时区的时间戳”。
https://www.postgresql.org/docs/9.5/static/datatype-datetime.html
https://www.postgresql.org/docs/9.5/static/datatype-datetime.html
回答by Jose Ospina
now I see that I had
现在我明白我有
<prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
instead of
代替
<prop key="hibernate.dialect">org.hibernate.dialect.PostgreSQLDialect</prop>