Yii Getting Obsolete Primary Key Sequence Name

I changed the name of a table in my Postgres database, and also changed the name of the corresponding primary key sequence. INSERTs work fine on the DB side.

Unfortunately, Yii is still trying to use the old sequence name. Is there some catalog table in Postgres that still needs updating, or is there a cache somewhere that I don’t know about? I’ve been trying to track down where Yii sets the $sequenceName variable, but have been getting lost in the layers.

Thanks for any assistance.

Haven’t studyed the postgres implementation in Yii… but as I see this… Yii does not need to know the sequence… as it’s a database job to insert the next value of such fields… but maybe I’m wrong…

As for cache… you can try to empty the "assets" and "runtime" folder, all cached/temporary files are there…

If you don’t solve this… post here the error you get with the stach trace… I will try to find where is the problem as I’m using postgres too on my job…

have you changed the model method of this?




public function tableName()

{

    return '{{new_table_name}}';

}



Exactly the same problem. I rename a table, sequence and all things linked to this table in order to have a coherency in naming. I have no problem to insert things using psql command in my shell, however yii gives me an error returns by DB such as the “old_name_id_seq” doesn’t exist. I don’t find from where it is. I searched in all my code and there is no more trace of the old_name table. I delete assets and runtime aswell…

When I print


 Yii::app()->db->getSchema()->getTable($this->tableName())->sequenceName 

I get the old and bad sequence name, how to refresh/reload the db schema ??

Did you update the default value of the primary key field to point to the new sequence?

I hit that some time ago. I don’t remember exactly, but maybe there is an assumption somewhere about naming the sequence after the column name.

Check the expression set as the default value for the PK in the table. If you use pgadmin3 also check it in psql to make sure, I remember that I saw a bug report in pgadmin3 about it.

yep, primary key default value is good on DB side with psql.

I Don’t have any cache, and try to remove all assets or runtime file… but it’s still not working.

any idea then ?

I can give you some points to check, but it’s all the same that has already been mentioned here:

  • you renamed the table

  • you renamed the sequence

  • you altered the table setting proper default value for the pk (that may not update itself when renaming the sequence)

  • you cleared the cache by removing contents of protected/runtime/cache

  • you test it issuing a manual query

  • you test it using ActiveRecord

If it still won’t work please post your table and sequence definition.

I am having the same problem. I change the sequence name of a table (Postgresql) But it still uses the old one. I try to clear schema cache using




Yii::app()->db->schema->getTables();

Yii::app()->db->schema->refresh();



and then, restart php. I am not sure where it is cached

This is all because of Yii way of getting sequences




class CPgsqlSchema method findColumns($table)



It search at pg_attrdef table for a sequence name, and this table contain obsoleted next val definition.

Here is the potgres doc about that table

www.postgresql.org/docs/8.2/static/catalog-pg-attrdef.html (can’t add links for a first post)

I solved this by alter column type from bigint to int and backward.

Thanks for suggesting this. My plan was to drop and add the serial column.

Altering table from bigint to integer and back, refreshes the pg_attrdef.adsrc fields. I’ve added this to migration and work for me.