autofield

How can I support AutoField(primary_key=False) in django?

被刻印的时光 ゝ 提交于 2020-08-24 08:18:42
问题 I need to add an autoinc field that is not the primary key. I am in the process of migrating a very large production database that uses autoincrementing fields to models.UUIDField . I have been doing a piecewise migration, and all of my relationships are now duplicated with both field types. I'm ready to make the primary key swap, but unfortunately I still need to keep the auto incrementing integer field for old clients as it becomes deprecated. Since django will not allow me to define an

How to declare a auto-incrementing alphanumerical id field with predefined aplphabetic part (Django python)

早过忘川 提交于 2020-04-17 22:51:28
问题 I am developing an app in Django. I want to insert in my model an auto-incrementing alphanumerical ID field, having, by default, a fixed alphabetical part and an auto-incrementing numerical part. But I also want the availability to change, from admin section, this id to another alphanumerical one, with a different alphanumerical and numerical part. Please note: I don't want to overwrite the django default id field, I just want to include in my model a field that gets as default value an auto

What is the proper way to manually sequence a column in Postgres?

烂漫一生 提交于 2019-12-10 13:53:31
问题 I have a SaaS pet project for invoicing. In it, I want my clients to each start with ticket number 1001. Clearly, I can't use a simple auto field in Postgres and just add 1000 to the value, because all my clients will share the same database and the same tickets table.. I've tried using an integer column type and querying (pseudo SQL) SELECT LATEST number FROM tickets WHERE client_id = [current client ID] to get the latest number, and then using that number + 1 to get the next number . The

How to get Django AutoFields to start at a higher number

你。 提交于 2019-11-27 18:50:02
For our Django App, we'd like to get an AutoField to start at a number other than 1. There doesn't seem to be an obvious way to do this. Any ideas? Like the others have said, this would be much easier to do on the database side than the Django side. For Postgres, it'd be like so : ALTER SEQUENCE sequence_name RESTART WITH 12345; Look at your own DB engine's docs for how you'd do it there. For MySQL i created a signal that does this after syncdb: from django.db.models.signals import post_syncdb from project.app import models as app_models def auto_increment_start(sender, **kwargs): from django

How to get Django AutoFields to start at a higher number

心不动则不痛 提交于 2019-11-27 04:19:21
问题 For our Django App, we'd like to get an AutoField to start at a number other than 1. There doesn't seem to be an obvious way to do this. Any ideas? 回答1: Like the others have said, this would be much easier to do on the database side than the Django side. For Postgres, it'd be like so: ALTER SEQUENCE sequence_name RESTART WITH 12345; Look at your own DB engine's docs for how you'd do it there. 回答2: For MySQL i created a signal that does this after syncdb: from django.db.models.signals import