cphalcon icon indicating copy to clipboard operation
cphalcon copied to clipboard

[BUG] Invalid sequence name for PosgreSQL

Open beermeat opened this issue 13 years ago • 8 comments

class SomeModel extends \PhalconMvc\Model
{
    public function getSchema()
    {
        return 'shemaname';
    }

    public function getSource()
    {
        return 'sometable';
    }
}

exception 'PDOException' with message 'SQLSTATE[42P01]: Undefined table: 7 ERROR: relation "sometable_id_seq" does not exist'

schema is missing, valid sequence name - "shemaname"."sometable_id_seq"

beermeat avatar Aug 07 '13 23:08 beermeat

You are at the time of inserting data error?

dreamsxin avatar Aug 08 '13 02:08 dreamsxin

I try fix it.

dreamsxin avatar Aug 08 '13 02:08 dreamsxin

I don't think this need a fix, you can implement the getSequenceName in the controller to tell the ORM which sequence must be used. http://docs.phalconphp.com/en/latest/reference/models.html#auto-generated-identity-columns

ghost avatar Aug 08 '13 03:08 ghost

@phalcon If i model set schema in PostgreSQL, An error occurs when you insert data, Of course, when the default public schema can not go wrong.

getSequenceName will return the full sequenceName it contains the schema?

dreamsxin avatar Aug 08 '13 03:08 dreamsxin

Yes, but that happens because the sequence name was not set:

class SomeModel extends \PhalconMvc\Model
{
    public function getSchema()
    {
        return 'shemaname';
    }

    public function getSource()
    {
        return 'sometable';
    }

    public function getSchemaName()
    {
           return 'sequence_name';
    }
}

ghost avatar Aug 08 '13 03:08 ghost

@phalcon You mean, like this, Will be right:

class SomeModel extends \PhalconMvc\Model
{
    public function getSchema()
    {
        return 'shemaname';
    }

    public function getSource()
    {
        return 'sometable';
    }

    public function getSequenceName()
    {
        return "shemaname.sometable_id_seq";
    }
}

dreamsxin avatar Aug 08 '13 03:08 dreamsxin

@sjinks How do you see Best to specify the schema for PostgreSQL

dreamsxin avatar Aug 08 '13 03:08 dreamsxin

@phalcon I've read the docs, of course getSequenceName() fix this issue. But I think framework itself must generate the correct common sequence name, otherwise it is a bug. getSequenceName() should be used if the sequence name is not a standard, but in this case it is a standard.

beermeat avatar Aug 08 '13 07:08 beermeat