我正在使用 plaframework 2.2.1,我已经创建了一个 MySQL 项目,但现在我想将我的项目转移到 PostgreSQL,但在重新创建数据库演变时遇到了一些错误。
我用于 mysql 的旧进化(1.sql)工作正常是:
# --- Created by Ebean DDL
# To stop Ebean DDL generation, remove this comment and start using Evolutions
# --- !Ups
create table product (
id bigint auto_increment not null,
name varchar(255),
price float,
constraint pk_product primary key (id))
;
create table shop (
id bigint auto_increment not null,
name varchar(255),
address_line1 varchar(255),
address_line2 varchar(255),
address_line3 varchar(255),
city varchar(255),
town varchar(255),
phone_number varchar(255),
owner_email varchar(255),
constraint pk_shop primary key (id))
;
create table user (
email varchar(255) not null,
password varchar(255),
first_name varchar(255),
last_name varchar(255),
constraint pk_user primary key (email))
;
create table product_shop (
product_id bigint not null,
shop_id bigint not null,
constraint pk_product_shop primary key (product_id, shop_id))
;
alter table shop add constraint fk_shop_owner_1 foreign key (owner_email) references user (email) on delete restrict on update restrict;
create index ix_shop_owner_1 on shop (owner_email);
alter table product_shop add constraint fk_product_shop_product_01 foreign key (product_id) references product (id) on delete restrict on update restrict;
alter table product_shop add constraint fk_product_shop_shop_02 foreign key (shop_id) references shop (id) on delete restrict on update restrict;
# --- !Downs
SET FOREIGN_KEY_CHECKS=0;
drop table product;
drop table product_shop;
drop table shop;
drop table user;
SET FOREIGN_KEY_CHECKS=1;
然后我删除了 1.sql 并为下面给出的 postgresql 重新创建了我的进化(1.sql)
# --- !Ups
create table member (
email varchar(255) PRIMARY KEY,
password varchar(255),
first_name varchar(255),
last_name varchar(255)
)
;
create table product (
id bigserial PRIMARY KEY,
name varchar(255),
price real
)
;
create table shop (
id bigserial PRIMARY KEY,
name varchar(255),
address_line1 varchar(255),
address_line2 varchar(255),
address_line3 varchar(255),
city varchar(255),
town varchar(255),
phone_number varchar(255),
email varchar(255) REFERENCES member
)
;
create table product_shop (
product_id bigint REFERENCES product ON DELETE RESTRICT,
shop_id bigint REFERENCES shop ON DELETE CASCADE,
PRIMARY KEY (product_id, shop_id)
)
;
这两个sql有什么区别吗?
我是否需要添加一些东西以使我的新 1.sql 函数等于我的 mysql 进化中的旧 1.sql 函数?我的新进化创建了我的数据库,但是当我尝试在我的商店表中插入值时,它显示相同的页面并且它的工作方式与使用 mysql 时不同,这意味着不加载下一页。在产品表中插入时会显示这一点。
[PersistenceException: Error getting sequence nextval]
In C:\Users\Myproject\app\models\Product.java at line 36.
33
34 public static Product create(String name,float price) {
35 Product product = new Product(name, price);
36 product.save();
37 product.saveManyToManyAssociations("shops");
38 return product;
39 }
40 public static void delete(Long id) {
41 find.ref(id).delete();
我也无法在 PgAdmin III 中找到由 2.sql 创建的数据库?