django-migrations

Rerun a Django data migration

自闭症网瘾萝莉.ら 提交于 2019-11-28 18:14:15
How would I rerun a data migration on Django 1.8+? If relevant, my migration is numbered 0011_my_data_migration.py and is the latest migration. Alasdair Fake back to the migration before the one you want to rerun. ./manage.py migrate --fake yourapp 0010_my_previous_data_migration Then rerun the migration. ./manage.py migrate yourapp 0011_my_data_migration Then you can fake back to the most recent migration that you have run. In your case, you said that 0011 was the latest, so you can skip this stage. ./manage.py migrate --fake yourapp 0014_my_latest_data_migration Note that depending on the

How to redo a migration on django 1.8 after using --fake

有些话、适合烂在心里 提交于 2019-11-28 17:25:47
Something went wrong on my migrations, I added a new datetimefield to a model then I used makemigrations and migrate. python manage.py makemigrations python manage.py migrate But after this the migrate got an "table already exists error". I supposed I could fake the migrations and start over, so I did python manage.py makemigrations --fake core Operations to perform: Apply all migrations: core Running migrations: Rendering model states... DONE Applying core.0001_initial... FAKED Applying core.0002_auto_20150525_1331... FAKED Applying core.0003_auto_20150525_1348... FAKED Applying core.0004

How to add a new field to a model with new Django migrations?

北战南征 提交于 2019-11-28 16:14:15
I'm using the contribute_to_class method but I don't know how to create the field in the database with new migrations. Nima To answer your question, with the new migration introduced in Django 1.7 , in order to add a new field to a model you can simply add that field to your model and initialize migrations with ./manage.py makemigrations and then run ./manage.py migrate and the new field will be added to your DB. To avoid dealing with errors for your existing models however, you can use the --fake : Initialize migrations for your existing models: ./manage.py makemigrations myapp Fake

Migration clashes with forms.py

♀尐吖头ヾ 提交于 2019-11-28 12:21:36
The command python manage.py makemigrations fails most of time due to the forms.py , in which new models or new fields are referenced at class definition level. So I have to comment each such definitions for the migration to operate. It's a painfull task. I don't understand why the migration process import the forms.py module. I think that importing models modules should be sufficient. Is there a way to avoid those errors ? I was having this same issue and found the specific problem. When the migrate command was being called, Django's system checks made their way into my forms.py and then

Adding django admin permissions in a migration: Permission matching query does not exist

点点圈 提交于 2019-11-28 09:56:16
I wanted to add some groups and assign permissions to them in a manually written migration but if I run it on a clean DB it creates permissions only after running all migrations. I've found this ticket: https://code.djangoproject.com/ticket/23422 but I cannot comment there (it's possible I was banned after expressing some discontent with GeoDjango docs), so I'll share an improvement over the solution there below. In django 1.10 the following code could be used: from django.contrib.auth.management import create_permissions def migrate_permissions(apps, schema_editor): for app_config in apps.get

expected string or buffer ,date_re.match(value) django error

落花浮王杯 提交于 2019-11-28 08:40:01
问题 I want to extent custom user model in django.I copy paste code from django official website. When i want to migrate it it throw error TypeError: expected string or buffer models.py education=models.CharField(max_length=13) from django.db import models from django.contrib.auth.models import ( BaseUserManager, AbstractBaseUser ) class MyUserManager(BaseUserManager): def create_user(self, email, date_of_birth, password=None): if not email: raise ValueError('Users must have an email address')

Upgrading from Django 1.6 to 1.9: python manage.py migrate failure

牧云@^-^@ 提交于 2019-11-28 08:02:23
问题 I'm running Django 1.6.6 on production and have recently upgraded to 1.9.7 on staging (dev server). This update was performed on the server and I followed the steps outlined here Upgrading from South. I noticed that the structure of the migration files have changed, and they no longer include a create statement. This causes issues because if I pull this new code from my GitHub repo and run python manage.py makemigrations or python manage.py migrate , it says: django.db.utils.OperationalError:

Change column type with django migrations

╄→гoц情女王★ 提交于 2019-11-28 07:37:52
问题 Consider this structure: some_table(id: small int) and I want change it to this: some_table(id: string) Now I do this with three migrations: Create a new column _id with type string (datamigration) Copy data from id to _id with string conversion Remove id and rename _id to id Is there a way to do this with only one migration? 回答1: You can directly change the type of a column from int to string. Note that, unless strict sql mode is enabled, integers will be truncated to the maximum string

Django - Cannot create migrations for ImageField with dynamic upload_to value

好久不见. 提交于 2019-11-28 06:20:41
I just upgraded my app to 1.7 (actually still trying). This is what i had in models.py: def path_and_rename(path): def wrapper(instance, filename): ext = filename.split('.')[-1] # set filename as random string filename = '{}.{}'.format(uuid4().hex, ext) # return the whole path to the file return os.path.join(path, filename) return wrapper class UserProfile(AbstractUser): #... avatar = models.ImageField(upload_to=path_and_rename("avatars/"), null=True, blank=True, default="avatars/none/default.png", height_field="image_height", width_field="image_width") When i try to makemigrations , it throws

How to migrate back from initial migration in Django 1.7?

心不动则不痛 提交于 2019-11-28 05:35:46
I created a new app with some models and now I noticed that some of the models are poorly thought out. As I haven't committed the code the sensible thing would be to migrate the database to last good state and redo the migration with better models. In this case the last good state is database where the new app doesn't exist. How can I migrate back from initial migration in Django 1.7? In South one could do: python manage.py migrate <app> zero Which would clear <app> from migration history and drop all tables of <app> . How to do this with Django 1.7 migrations? ChillarAnand You can do the same