currval of sequence "sample_id_seq" is not yet defined in this session

1,718 views
Skip to first unread message

wilbur

unread,
May 18, 2011, 2:48:12 PM5/18/11
to Django users
Hello,

I have changed a number of field names and definitions in my models,
and when I try to add a new record in the Django administration, I get
the following error:

currval of sequence "sample_id_seq" is not yet defined in this session

When I look at the relevant postgresql table, the sequence for the id
is named:

id | integer | not null default
nextval('sample_id_seq1'::regclass)

Note: the slight change in name defined in the postgres table, and the
name of the sequence that Django is looking for.

How might I deal with this discrepancy?

Shawn Milochik

unread,
May 18, 2011, 2:55:18 PM5/18/11
to django...@googlegroups.com
You have three choices.

1. Use South. #1 recommendation by me.
http://south.aeracode.org/

2. Delete your entire database and do another syncdb.

3. Write SQL manually to fix your database (don't do this).

The reason is that, once you do syncdb and a table is created, running
syncdb will never again touch that table. You need a schema migration
tool (South) for that.

Note that if you decide to use South and want to keep your existing
data, you'll have to revert your models.py to the state it was in during
the initial syncdb, create your 'initial' south migration, then make the
changes. Then you'll be able to use South to automatically create a
migration.

Shawn


wilbur

unread,
May 18, 2011, 3:32:05 PM5/18/11
to Django users
Thanks for responding Shawn,

I am using south, and have tried using a schemamigration --auto on the
database...
I get the error:

? The field 'Photo_Log.sample_id' does not have a default specified,
yet is NOT NULL.
? Since you are removing this field, you MUST specify a default
? value to use for existing rows. Would you like to:
? 1. Quit now, and add a default to the field in models.py
? 2. Specify a one-off value to use for existing columns now
? 3. Disable the backwards migration by raising an exception.

I tried 2 things without success, and continued to get this same error
message.

1. With the postgresql table defining the sample_id as NOT NULL, I set
the default=0 in the model definition for this foreign key
e.g. sample = models.ForeignKey(Sample, verbose_name='Sample Name',
default=0).

2. Removed the postgresql NOT NULL constraint on the column sample_id
and set the model definition to:
e.g. sample = models.ForeignKey(Sample, verbose_name='Sample Name').

I get the same error regardless??






On May 18, 12:55 pm, Shawn Milochik <sh...@milochik.com> wrote:
> You have three choices.
>
> 1. Use South. #1 recommendation by me.http://south.aeracode.org/

Shawn Milochik

unread,
May 18, 2011, 3:37:44 PM5/18/11
to django...@googlegroups.com
Making manual changes to the database won't make a difference, as South
just checks your Python models and not the database itself.

In this case I'd set 'null = True, blank = True' in the model and run
the migration.

Then, if this really is a required field, then you should create a
datamigration with South to populate it, then remove the above flags and
create another schemamigration (with --auto) to make the field required
again.

Also, read the choices South gave you in the error message; maybe one
will work for you.


William Hudspeth

unread,
May 18, 2011, 4:41:36 PM5/18/11
to django...@googlegroups.com
pg_dump -C -h localhost -U wilbur -t achon_group -t achon_grouping -t
brecciation -t chon_class -t chon_group -t chon_petro -t
chon_petro_subtype -t iron_group -t iron_struc -t loan -t met_type -t
metrefs1 -t other_notes -t photo_log -t sample -t sample_exporterrors -t
specimen -t specimen_type -t stony_iron_grouping iom_metcat | psql -h
129.24.63.74 -U wilbur iom_metcat

Gabriel Gunderson

unread,
May 19, 2011, 4:34:52 AM5/19/11
to django...@googlegroups.com


Do you have a question? About Django?

Gabe

Reply all
Reply to author
Forward
0 new messages