4👍
✅
Hmm… and what about explicitly write id field in the model definition? Like this for example:
class Entry(models.Model):
id = models.AutoField(verbose_name="custom name")
# and other fields...
It doesn’t require any underlying database changes.
2👍
Look into the command-line options for manage.py
; there’s a command to dump all of the model data to JSON, and another command to load it back in from JSON. You can export all of your model data, add your new field to the model, then import your data back in. Just make sure that you set the db_column
option to 'id'
so you don’t break your existing data.
Edit: Specifically, you want the commands dumpdata
and loaddata
.
- [Django]-Adding javascript to an extended django template for google analytics
- [Django]-How to get a foreignkey object to display full object in django rest framework
- [Django]-How to put absolute url field in serializer model in django rest framework?
- [Django]-Cannot Connect to Django from outside the Local Server
- [Django]-How to get a word count on word document in python?
Source:stackexchange.com