Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PostgreSQL using sequences issue #853

Closed
morrigan opened this issue Sep 26, 2016 · 5 comments
Closed

PostgreSQL using sequences issue #853

morrigan opened this issue Sep 26, 2016 · 5 comments

Comments

@morrigan
Copy link

morrigan commented Sep 26, 2016

Hi,
this is the issue I am facing when running migrations on production. Any tips? Using Phalcon DevTools (2.0.13).

Error:

CREATE TABLE "public"."images" (
  "id" BIGSERIAL DEFAULT "nextval('images_id_seq'::regclass)" NOT NULL,
  "base64" TEXT
);
ERROR: SQLSTATE[42601]: Syntax error: 7 ERROR:
multiple default values specified for column "id" of table "images"

Generated migration file:

<?php

use Phalcon\Db\Column;
use Phalcon\Db\Index;
use Phalcon\Db\Reference;
use Phalcon\Mvc\Model\Migration;

/**
 * Class ImagesMigration_101
 */
class ImagesMigration_101 extends Migration
{
    /**
     * Define the table structure
     *
     * @return void
     */
    public function morph()
    {
        $this->morphTable('images', array(
                'columns' => array(
                    new Column(
                        'id',
                        array(
                            'type' => Column::TYPE_BIGINTEGER,
                            'default' => "nextval('images_id_seq'::regclass)",
                            'notNull' => true,
                            'autoIncrement' => true,
                            'first' => true
                        )
                    ),
                    new Column(
                        'base64',
                        array(
                            'type' => Column::TYPE_TEXT,
                            'size' => 1,
                            'after' => 'id'
                        )
                    )
                ),
                'indexes' => array(
                    new Index('pk_image_id', array('id'), null)
                ),
            )
        );
    }

    /**
     * Run the migrations
     *
     * @return void
     */
    public function up()
    {

    }

    /**
     * Reverse the migrations
     *
     * @return void
     */
    public function down()
    {

    }

}
@sergeyklay
Copy link
Contributor

sergeyklay commented Sep 26, 2016

Hi @morrigan,

Thanks for contributing!
It seems this is Phalcon issue. Correct SQL is:

CREATE TABLE "public"."images" (
  -- NOTE:
  -- Without > DEFAULT "nextval('images_id_seq'::regclass)" NOT NULL
  "id" BIGSERIAL,
  "base64" TEXT
);

Or:

CREATE TABLE "public"."images" (
  -- NOTE:
  -- Without > DEFAULT "nextval('images_id_seq'::regclass)"
  "id" BIGSERIAL NOT NULL,
  "base64" TEXT
);

as workaround try to comment

'default' => "nextval('images_id_seq'::regclass)",

new Column(
    'id',
    array(
        'type' => Column::TYPE_BIGINTEGER,
        // 'default' => "nextval('images_id_seq'::regclass)",
        'notNull' => true,
        'autoIncrement' => true,
        'first' => true
    )
)

@morrigan
Copy link
Author

@sergeyklay Yeah, I don't get the error when default propery is removed and seems like auto incrementation still works :)

@sergeyklay
Copy link
Contributor

@morrigan I'll fix this ASAP

@sergeyklay
Copy link
Contributor

sergeyklay commented Sep 28, 2016

@morrigan
I've fixed Phalcon issue in the Phalcon 3.0.x branch. So now migration must be created in the right way.

Could you please check the Phalcon 3.0.x branch?

git clone git@github.com:phalcon/cphalcon.git
cd cphalcon
git checkout 3.0.x

zephir fullclean
zephir build

sergeyklay added a commit that referenced this issue Sep 28, 2016
@sergeyklay
Copy link
Contributor

I've added hotfix in Devtools 3.0.x branch #864

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants