Questions tagged [autofield]

24 questions
30
votes
9 answers

How to get Django AutoFields to start at a higher number

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?
user9845
  • 303
  • 1
  • 3
  • 5
9
votes
3 answers

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

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…
Ryan Romanchuk
  • 10,819
  • 6
  • 37
  • 41
6
votes
3 answers

django admin gives warning "Field 'X' doesn't have a default value"

I have created two models out of an existing legacy DB , one for articles and one for tags that one can associate with articles: class Article(models.Model): article_id = models.AutoField(primary_key=True) text =…
olamundo
  • 23,991
  • 34
  • 108
  • 149
5
votes
2 answers

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

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…
orokusaki
  • 55,146
  • 59
  • 179
  • 257
3
votes
2 answers

Liferay.AutoFields and DatePicker in Liferay

I have the requirement to duplicate a set of input fields on click of a button; as many times as required. This feature is same like we do have in LIferay: Goto "Control panel -> User", click on any user. On right side of the page, under…
Tina Agrawal
  • 616
  • 9
  • 16
2
votes
2 answers

Django: non primary-key auto incremented field

is there a possible way to create a non primary-key auto incremented field like a AutoField/BigAutoField that is not prone to failure(duplicated ids, ...) ?
Django DO
  • 167
  • 3
  • 13
2
votes
1 answer

Django add prefix to AutoField

Is there a way to create an AutoField in Django that always begins with a certain prefix? I would like to create an AutoField that always begin with the number 1, where the first 15 saved records would have the values 11, 12, 13, 14, ..., 19, 110,…
touch my body
  • 1,634
  • 22
  • 36
2
votes
2 answers

IntegrityError after table restore from backup, PostgreSQL + Django

I am trying to restore a table in my database from some db backups. The backup is created via pgAdmin 4 UI tool, select a table and next backup it. And here is the command that pgAdmin executes: --file…
Chiefir
  • 2,561
  • 1
  • 27
  • 46
2
votes
0 answers

Any atomic way in Django to force Postgres's AutoField sequence to be updated on explicit insertions?

While converting our monolith service to Django micro-services, we are migrating to Postgres a table of users from our old DB. The users table have a primary 'user_id' field. At first phase of our migration, we will write new users to both DB's, and…
adibi
  • 41
  • 3
1
vote
1 answer

How do I set up a model to use an AutoField with a legacy database in Python?

I have a legacy database with an integer set as a primary key. It was initially managed manually, but since we are wanting to move to django, the admin tool seemed to be the right place to start. I created the model and am trying to set the primary…
Joshua
  • 26,234
  • 22
  • 77
  • 106
1
vote
3 answers

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

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…
Tms91
  • 3,456
  • 6
  • 40
  • 74
1
vote
1 answer

How to set initial value of primary key in django

I made this django model: class Car(models.Model): car_id = models.AutoField(primary_key=True) engine_size = models.FloatField() fuel_consumption = models.FloatField() def __str__(self): return(str(self.car_id)) The…
1
vote
0 answers

Liferay Autofield with DatePicker

I have a aui form with Liferay.Autofields enabled. The fields that I am duplicating with Autofield has a button and a textfield. The button click will trigger the datepicker and the selected value should be stored in the textfield. And, when I click…
Kiran Kulkarni
  • 1,434
  • 2
  • 18
  • 40
1
vote
2 answers

Django: Edit ModelForm using AutoField

I'm trying to make a view where the user can edit DB records through a form in a template. I've searched a lot of web pages (and Django docs as well) where they teach how to make these views, but they always use the "id" that Django generates for…
user1106551
0
votes
1 answer

Inherited Classes Django - Id of manually created parent is not generated even after save, the pointer of child also not working

Problem explanation Hello I have been having some issues with saving a many to many field when trying to inherit from another class. I have overwritten the save function for my "CharacterBanner" class which extends my "Banner" class. I attempt to…
Bernoulli
  • 1
  • 1
1
2