Django migration with uuid field generates duplicated values

Here is an example doing everything in one single migration thanks to a RunPython call. # -*- coding: utf-8 -* from __future__ import unicode_literals from django.db import migrations, models import uuid def create_uuid(apps, schema_editor): Device = apps.get_model(‘device_app’, ‘Device’) for device in Device.objects.all(): device.uuid = uuid.uuid4() device.save() class Migration(migrations.Migration): dependencies = [ (‘device_app’, ‘XXXX’), ] operations … Read more

Django Programming error column does not exist even after running migrations

I got the same problem (column not exist) but when I try to run migrate not with makemigrations (it is the same issue I believe) Cause: I removed the migration files and replaced them with single pretending intial migration file 0001 before running the migration for the last change Solution: Drop tables involved in that … Read more

Django Migrations Add Field with Default as Function of Model

I just learned how to do this with a single migration! When running makemigrations django should ask you to set a one-off default. Define whatever you can here to keep it happy, and you’ll end up with the migration AddField you mentioned. migrations.AddField( model_name=”series”, name=”updated_as”, field=models.DateTimeField(default=????, auto_now=True), preserve_default=False, ), Change this one operation into 3 … Read more

django 1.7 migrate gets error “table already exists”

If you have the table created in the database, you can run python manage.py migrate –fake <appname> Mark migrations as run without actually running them Or if you want to avoid some actions in your migration, you can edit the migration file under the app/migrations directory and comment the operations you don’t want to do … Read more

Django migration strategy for renaming a model and relationship fields

So when I tried this, it seems you can condense Step 3 – 7: class Migration(migrations.Migration): dependencies = [ (‘myapp’, ‘0001_initial’), ] operations = [ migrations.RenameModel(‘Foo’, ‘Bar’), migrations.RenameField(‘AnotherModel’, ‘foo’, ‘bar’), migrations.RenameField(‘YetAnotherModel’, ‘foo’, ‘bar’) ] You may get some errors if you don’t update the names where it’s imported e.g. admin.py and even older migration files … Read more

tech