django-migrations

“No installed app with label 'admin'” running Django migration. The app is installed correctly

与世无争的帅哥 提交于 2019-11-29 16:09:28
问题 I am trying to use admin.LogEntry objects during a datamigration on Django 1.7 The 'django.contrib.admin' app is listed on INSTALLED_APPS . On the shell, it works: >>> from django.apps import apps >>> apps.get_model('admin', 'LogEntry') django.contrib.admin.models.LogEntry But during the migration, it fails: def do_it(apps, schema_editor): LogEntry = apps.get_model('admin', 'LogEntry') Fails like this: django-admin migrate (...) LookupError: No installed app with label 'admin'. Using a

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

不想你离开。 提交于 2019-11-29 14:03:28
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: no such table: appname_modelname The traceback points to my urls.py because I'm referencing the model

Django Heroku Error “Your models have changes that are not yet reflected in a migration”

旧城冷巷雨未停 提交于 2019-11-29 12:06:21
问题 I recently added a model to my app (UserProfile) and when I pushed the changes to Heroku, I think I accidentally ran heroku run python manage.py makemigrations . Now when I try to run heroku run python manage.py migrate I get the error below (leaguemaster) benjamins-mbp-2:leaguemaster Ben$ heroku run python manage.py migrate Running `python manage.py migrate` attached to terminal... up, run.1357 Operations to perform: Synchronize unmigrated apps: allauth Apply all migrations: auth, admin,

How to create GIN index in Django migration

三世轮回 提交于 2019-11-29 09:58:10
In Django, since version 1.11 we have a class for PostgreSQL GinIndex ( https://docs.djangoproject.com/en/1.11/ref/contrib/postgres/indexes/ ). I'd like to create a migration that constructs such index on a VectorSearchField I added to one of my tables. So far, I've tried to simply add db_index=True to the VectorSearchField , but that fails, because it tries to create a B-Tree index (I think) and the VectorSearchField values are too long. I managed to create the index I want by running a migrations.RunSQL() migration with: CREATE INDEX entryline_sv_index ON entryline USING GIN (sv); However, I

How to squash recent Django migrations?

懵懂的女人 提交于 2019-11-29 05:15:58
问题 In Django's migrations code, there's a squashmigrations command which: "Squashes the migrations for app_label up to and including migration_name down into fewer migrations, if possible." So, if you want to squash, say, the first 5 migrations, this will help. What's the best way to squash starting with a particular migration_name ? In a project I'm currently working on, we've added 5-10 new migration files as we've added new features. We'll deploy the whole project at once and it looks like

defining a custom post_migrate signal

一个人想着一个人 提交于 2019-11-29 02:06:41
I'm doing some kind of refactoring for my project, where I'm relying on the django django.contrib.auth.models.Permission model. So far I define the permissions for each new user using a post_save signal, so when the user is created, I assign their permissions using user.user_permissions.add(the_permission) , this works perfectly. Now I want to use the django.contrib.auth.models.Group model to clasify the permissions a user should have. This is my code: from django.apps import AppConfig from django.db.models.signals import post_migrate from django.contrib.auth.models import Group, Permission

--fake-initial vs --fake in Django migration?

半腔热情 提交于 2019-11-29 01:12:35
What is the difference between --fake-initial and --fake in Django migrations? What are the dangers of using fake migrations? Anybody knows? Thank you very much to all. I am using django 1.10 e4c5 Well the documentation is very clear about this --fake-initial Allows Django to skip an app’s initial migration if all database tables with the names of all models created by all CreateModel operations in that migration already exist. This option is intended for use when first running migrations against a database that preexisted the use of migrations. This option does not, however, check for

Django migration with uuid field generates duplicated values

家住魔仙堡 提交于 2019-11-28 22:29:41
I have a uuid field (not a primary key). The generated migration is: from __future__ import unicode_literals from django.db import migrations, models import uuid class Migration(migrations.Migration): dependencies = [ .... ] operations = [ ... migrations.AddField( model_name='device', name='uuid', field=models.UUIDField(default=uuid.uuid4, unique=True), ), ... ] But when doing python manage.py migrate it is crashing with: django.db.utils.IntegrityError: could not create unique index "restaurants_device_uuid_key" DETAIL: Key (uuid)=(f3858ded-b8e0-4ac0-8436-8a61b10efc73) is duplicated. Strangely

Django Migrations Add Field with Default as Function of Model

六眼飞鱼酱① 提交于 2019-11-28 19:07:19
I added a new, non-nullable field to my Django model and am trying to use migrations to deploy that change. How would I set default value to use for existing models to be some function of those models rather than a constant? As an example let's say I previously had a created_on field and I just added an updated_on field whose value I want to set initially to the model's created_on . How would I do this in a migration? This is what I am trying to start with: migrations.AddField( model_name='series', name='updated_as', field=models.DateTimeField(default=????, auto_now=True), preserve_default

Django migrations RunPython not able to call model methods

和自甴很熟 提交于 2019-11-28 19:07:17
I'm creating a data migration using the RunPython method. However when I try to run a method on the object none are defined. Is it possible to call a method defined on a model using RunPython ? chhantyal Model methods are not available in migrations, including data migrations. However there is workaround, which should be quite similar to calling model methods. You can define functions inside migrations that mimic those model methods you want to use. If you had this method: class Order(models.Model): ''' order model def goes here ''' def get_foo_as_bar(self): new_attr = 'bar: %s' % self.foo