2016-06-12 16:38
采纳率: 100%
浏览 62

Propel2 diff使用PostgreSQL检测不存在的更改

I'm using Propel2 ORM w/ PostgreSQL, this is my configuration:

            adapter: pgsql
            dsn: pgsql:host=localhost;port=5432;dbname=sps_db
            user: postgres
            password: postgres
                charset: utf8

This is my sample schema:

<?xml version="1.0" encoding="utf-8"?>
<database name="default" defaultIdMethod="native" defaultPhpNamingMethod="underscore" xmlns:xsi=""
      xsi:noNamespaceSchemaLocation="" >
<table name="product" description="Available products table">
    <column name="id_product" autoIncrement="true" primaryKey="true" type="BIGINT" required="true"/>
    <column name="id_product_barcode" type="BIGINT" />
    <column name="name" type="VARCHAR" size="200" required="true" />
    <column name="id_product_manufacturer" type="INTEGER" required="true" />
    <column name="id_product_category" type="INTEGER" required="true"/>
    <column name="id_product_photo" type="BIGINT" />

PostgreSQL 9.5 has been fresh installed on Ubuntu 16.04. When I run propel diff and propel migrate the first time everything is OK and the tables are generated.

Here is the first generated migration:

If, without changing the schema, I re-run diff propel detects changes (which are non-existent):

Comparing models...
Structure of database was modified in datasource "default": 1 modified tables

With the following generated migration file:

Of course, if I execute the migration file SQL complains:

  SQLSTATE[42701]: Duplicate column: 7 ERROR:  column "id_product" of relation "product" already exists  

I can't really figure out what's happening. All of the above, with a much more complex schema (and with this one, too) works correctly w/ MySQL.

Any ideas?

EDIT: this is the SQL from pgSql for the table generated in the first migration:

CREATE TABLE public.product
  id_product bigint NOT NULL DEFAULT nextval('product_id_product_seq'::regclass),
  id_product_barcode bigint,
  name character varying(200) NOT NULL,
  id_product_manufacturer integer NOT NULL,
  id_product_category integer NOT NULL,
  id_product_photo bigint,
  CONSTRAINT product_pkey PRIMARY KEY (id_product)
ALTER TABLE public.product
  OWNER TO postgres;
COMMENT ON TABLE public.product
  IS 'Available products table';
  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • dr637349
    dr637349 2016-06-14 18:04

    Downgrading PostgreSQL 9.5.x to 9.4.8 solved this problem for me.

    It may be a bug in 9.5.x.

    点赞 评论
  • dongshi2588
    dongshi2588 2016-08-22 06:09

    After some debugging and investigation (we figured it was a 9.5 metadata change) we found the following:

    It comes down to a simple trim command when splitting the schema in postgresql 9.5

    点赞 评论