5👍
The problem is that the Ticket_generateUniqueID
method used to get the default value is attempting to fetch a column that the migration has not created yet.
try:
t = Ticket.objects.get(ticket_number=retval)
pass
except ObjectDoesNotExist:
return retval
In this case, I think you can avoid the problem by changing your method to use exists()
instead of get()
.
if Ticket.objects.filter(ticket_number=retval).exists():
pass
else:
return retval
If it wasn’t possible to rewrite the default method, then it would be trickier to fix. I believe that you would have to add a data migration before the migration that is causing the errors, and set the field values there. In the data migration, you could use Ticket = apps.get_model('myapp', 'Ticket')
. You would then be able to run Ticket.objects.get()
without any errors.
0👍
Just one update: when I deleted all migrations and recreated them as one simple, my tests starts to fail with:
django.db.utils.OperationalError: no such table: tickets_ticket
as my tests created (and not saved) Ticket objects before loading fixture with data so I added this sanity test before the while cycle:
if not( u'tickets_ticket' in connection.introspection.table_names()):
return generateID() # if no table exists, none ID exists too, so anything is unique :)
# --- now find unique value
- [Django]-A different virtualenv for each Django app
- [Django]-How to add TokenAuthentication authentication classes to Django FBV
- [Django]-Using Django with MySQL for storing and looking up Large DNA Microarray Results
- [Django]-Django model managers.py and models.py