On Monday 19 June 2017 16:29:48 Thomas Hauk wrote:
> I am working on a project that uses Django 1.10.5 with Postgres 9.6
> (and Python 3.6.1).
> 
> I am currently migrating historical data from an old system into the
> new system. This historical data has a table with a (non-primary key)
> "ID" column. I would like to migrate these rows into the new
> database, and have that column be auto-incrementing (starting from,
> say, 100000) for new rows inserted.
> 
> I think the way to do this with raw Postgres SQL would be to create a
> serial field, and then run a SQL command like "SELECT
> SETVAL('some_table_field_id_seq', 100000)". I think.  :)
> 
> Does Django expose functionality that lets me accomplish this?

First and foremost, verify if ID meets your requirements:
- All values are unique
- They are integers
- Their values are smaller then your new cut-off (100000)

Then you can simply transform the field explicitly to primary key and then to 
BigAutoField. 
Setting the next value can be done using RunSQL[1].

-- 
Melvyn Sopacua

--------
[1] https://docs.djangoproject.com/en/1.11/ref/migration-operations/#runsql

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/2739441.8eksa7p7ra%40devstation.
For more options, visit https://groups.google.com/d/optout.

Reply via email to