django-migrations

Django migration fails with “__fake__.DoesNotExist: Permission matching query does not exist.”

天涯浪子 提交于 2019-12-10 01:00:48
问题 In a Django 1.8 project, I have a migration that worked fine, when it had the following code: # -*- coding: utf-8 -*- from __future__ import unicode_literals from django.db import migrations from django.conf import settings def update_site_forward(apps, schema_editor): """Add group osmaxx.""" Group = apps.get_model("auth", "Group") Group.objects.create(name=settings.OSMAXX_FRONTEND_USER_GROUP) def update_site_backward(apps, schema_editor): """Revert add group osmaxx.""" Group = apps.get_model

django.db.utils.IntegrityError: column “venue_city” contains null values

∥☆過路亽.° 提交于 2019-12-09 15:46:44
问题 I have read a lot of other posts here on stackoverflow and google but I could not find a solution. It all started when I changed the model from a CharField to a ForeignKey. The error I recieve is: Operations to perform: Synchronize unmigrated apps: gis, staticfiles, crispy_forms, geoposition, messages Apply all migrations: venues, images, amenities, cities_light, registration, auth, admin, sites, sessions, contenttypes, easy_thumbnails, newsletter Synchronizing apps without migrations:

Why does Django create migration files for proxy models?

落爺英雄遲暮 提交于 2019-12-09 14:21:56
问题 I just created a proxy model and was surprised that manage.py makemigrations creates a new migration file with a migrations.CreateModel operation. A proxy model does not create a new database table, it's just a different python interface to the same dataset and indeed manage.py sqlmigrate my_app_label 0042 returns nothing. I thought that it might be used to create the proxy model ContentType but those are created on demand if they don't exist. Is it used to trigger the creation of the proxy

Django 1.7 makemigrations renaming tables to None

烈酒焚心 提交于 2019-12-08 21:06:29
问题 I had to move a few models from one app to another, and I followed the instructions on this answer https://stackoverflow.com/a/26472482/188614. Basically I used the CreateModel migrations generated by python manage.py makemigrations , wrapped them inside state_operations , and added the 'db_table' meta option with the old table's name. Everything works fine, the models on the new_app are corretly using the old tables. But if I run python manage.py makemigrations new_app it creates an

Django Migrations Says Database Backend Isn't Available

落花浮王杯 提交于 2019-12-08 20:16:17
问题 I'm trying to upgrade a Django 1.6.2 application to 1.7.10. I'm running PostgreSQL on my Mac using the Postgres.app version 9.3.4 that runs PostgreSQL 9.3.4 and PostGIS 2.1.1. The problem I'm having is that when I run the new "makemigrations" command, I'm getting the following error (the entire stacktrace is at the bottom): django.core.exceptions.ImproperlyConfigured: 'django.contrib.gis.db.backends.postgis' isn't an available database backend. Try using 'django.db.backends.XXX', where XXX is

Default value for foreign key in Django migrations.AddField

ぃ、小莉子 提交于 2019-12-08 16:39:31
问题 Using migrations, I need to add a new field (a foreign key) to a model. I know it can be done with: migrations.AddField( model_name='MyModel', name='state', field=models.ForeignKey(null=True, related_name='mymodel_state', to='msqa_common.MyModelState'), ), However, I don't want my field to be nullable. Instead, I want to use a default value for it, corresponding to the id of MyModelState whose name is "available" (id value might change in different machines). This "available" value of table

Django migrations and deconstructible string

杀马特。学长 韩版系。学妹 提交于 2019-12-08 16:38:32
I have to create a class which instances must fit two conditions: being an str subclass so that it can be passed to os.listdir() being deconstructible so that the string does not appear as-is when django generates migrations, but as mailing.conf.StrConfRef('another string') Here is what I tried: class StrConfRef(str): def __new__(cls, name, within=None): value = globals()[name] if within: value = within.format(value) self = str.__new__(cls, value) self.name = name self.within = within return self def deconstruct(self): return ('{}.{}'.format(__name__, self.__class__.__name__), (self.name,), {

django migration hell, dropped a table. Tried to get it back

倖福魔咒の 提交于 2019-12-08 06:45:34
问题 So I dropped a table in my database, and I want it back. Rerunning a migration gave errors table didn't exist. After some hunting I learned I could remove everything in my django_migrations that had app name my app. So i did that, reran migrations it started to work then griped about tables that were not dropped. I have no idea how to just get the one table back again and keep everything as it was... anyway to do this? I don't care about 90% of the data in the database, only a few tables and

Django migrations and deconstructible string

走远了吗. 提交于 2019-12-08 03:47:37
问题 I have to create a class which instances must fit two conditions: being an str subclass so that it can be passed to os.listdir() being deconstructible so that the string does not appear as-is when django generates migrations, but as mailing.conf.StrConfRef('another string') Here is what I tried: class StrConfRef(str): def __new__(cls, name, within=None): value = globals()[name] if within: value = within.format(value) self = str.__new__(cls, value) self.name = name self.within = within return

Django: Providing initial group with migrations

泄露秘密 提交于 2019-12-07 13:08:21
问题 Since the using of an initial_data fixture is deprecated, I'm trying to add initial data with a migration. I created my models, and one of the models contains a permission code-named can_use_feature . When I run a makemigrations , a 0001_initial.py migration is created. The migrate command creates the database, well populated and the permission from above is in the auth_permission table. Now I want to have a group with that permission by default in the database, so I create this migration as