FAQ Database Discussion Community


How to delete django migrations after squashing them?

django,migration,django-migrations,squash
Django documentation says we could delete migrations after squashing them: You should commit this migration but leave the old ones in place; the new migration will be used for new installs. Once you are sure all instances of the code base have applied the migrations you squashed, you can delete...

Django 1.8: migrations break with AbstractBaseUser

django,django-models,django-migrations,django-1.8
I have a working Django 1.6 project than I'm upgrading to 1.8. I have a custom user model in app mainapp that looks like this: class CustomUser(AbstractBaseUser, PermissionsMixin): ... manage.py migrate or syncdb fail with the following error: Operations to perform: Synchronize unmigrated apps: gis, gunicorn, staticfiles, guardian, messages, captcha,...

Django migrations

python,django,django-migrations
I am trying to build a blog on django. I have gone as far as creating models. Here they are: from django.db import models import uuid class Users(models.Model): username = models.CharField(max_length = 32, primary_key = True) password = models.CharField(max_length = 32) email = models.EmailField() registration_date = models.DateTimeField(auto_now_add = True) class...

Django proxy model cannot be migrated when upgrading 1.4 -> 1.7

django,django-models,django-migrations
Having a model like below from django.contrib.auth.models import User # has migrations in 1.7 class MyProxyUser(User): class Meta: proxy = True in an app without migrations gives the following error when running the tests: django.db.migrations.state.InvalidBasesError: Cannot resolve bases for [<ModelState: 'django_proxy_model_problems.MyProxyUser'>] This can happen if you are inheriting models from...

Django 1.8: Create initial migrations for existing schema

django,django-migrations
I started a django 1.8 project, which uses the migrations system. Somehow along the way things got messy, so I erased the migrations folders and table from the DB, and now I'm trying to reconstruct them, with no success. I have three apps (3 models.py files), and the models reflect...

Django 1.7.3 - Lookup failed for model referenced by field

python,django,postgresql,django-migrations
I am trying create a new model with Django, but I keep running into the error Lookup failed for model referenced by field help.HelpDefinition.org: account.Organization. Organization has been imported. You can see the model below. models.py org = models.ForeignKey(Organization, unique=True) help_type = models.CharField(max_length=255, choices=HELP_CHOICES) help_content = models.TextField(blank=True) This model has...

Django 1.8 Circular Dependecy error

python,django,django-migrations
I'm having trouble finding solutions to this problem online. All I have is "To manually resolve a CircularDependencyError, break out one of the ForeignKeys in the circular dependency loop into a separate migration, and move the dependency on the other app with it. If you’re unsure, see how makemigrations deals...

So, I have a Django migrate error when removing classes and their subclasses at the same time, which appears as an sql syntax error, with sqlite3

python,django,sqlite3,django-migrations
I have an error when migrating my models, and I think it's due to the way I'm setting a 'limit_choices_to' containing quotes etc. Migrations for 'characters': 0005_auto_20150129_1019.py: - Remove field attribute from dicepool - Remove field contested_dicepool from dicepool - Remove field resisted_by_attribute from dicepool - Remove field second_attribute from...

Do django db_index migrations run concurrently?

django,django-south,django-migrations
I'm looking to add a multi-column index to a postgres database. I have a non blocking SQL command to do this which looks like this: CREATE INDEX CONCURRENTLY shop_product_fields_index ON shop_product (id, ...); When I add db_index to my model and run the migration, will it also run concurrently or...

How to create table during Django tests with managed = False?

python,django,django-testing,django-1.7,django-migrations
From the oficial documentation: For tests involving models with managed=False, it’s up to you to ensure the correct tables are created as part of the test setup. I don't know how to create the tables as part of the test setup. I found this question and the accepted answer doesn't...

Django migrations detect the same change many times

django,django-models,django-migrations
I have a model like this: MyModel(models.Model): ... date_start = models.DateTimeField( auto_now=True, editable=True ) date_end = models.DateTimeField( default=datetime.now() + relativedelta(months=3) ) ... I modified the date_end field before, and I did the migrations, it is working properly, but now it is still detecting that change as a new migration. Any...

Can I delete the django migration files inside migrations directory

python,django,django-migrations
I personally like django for its MVC ideals. But while i am running Django migrations in version 1.7 each and every migrations i do in it is stored inside the migrations directory. If i delete those file it is throwing an error while migration. I Tested like this. I created...

Django 1.7 Migration Errors when deploying on Heroku

python,django,heroku,deployment,django-migrations
Python and Django newbie here. Part of my code is based on the video tutorial Launch with Code from Coding for Entrepreneurs. Using Python 2.7.5 with Django 1.7.4 and trying to deploy my app on Heroku, I get stuck with an error I don't understand when synchronizing the database. I...

Django migrations reference a deleted module

django,migration,django-migrations
I have a Model named FooModel defined in a my_app/models/foo.py. After deleting foo.py, running Django (1.7) migrations raises an error since the old migration files import foo.py (import myapp.models.foo.FooModel). How should I resolve this? This happens when the model has an ImageField with an upload_to parameter....

Django 1.7 Not Finding New Model w/ makemigrations

python,django,django-migrations
I have a project with several apps and many data models. I'm using Django 1.7 and Python 2.7. I've organized the models into app-level modules. - common/ -- models/ --- __init__.py --- these_models.py --- those_models.py I've added a new file in this structure and Django's makemigration command is not detecting...

Is it safe to rename Django migrations file?

django,django-migrations
Since Django 1.8 the makemigrations command has a --name, -n option to specify custom name for the created migrations file. I'd like to know whether it's safe in older versions of Django to create the migrations file with the automatically generated name and then rename the file manually. It seems...

Django migrate error name 'bPath' is not defined

django,django-models,django-migrations
I'm running on Django 1.7.4. # base.py PRIVATE_FOLDER_ROOT = str(PROJECT_DIR.child('web_private')) # tested: PRIVATE_FOLDER_ROOT = PROJECT_DIR.child('web_private') # tested: PRIVATE_FOLDER_ROOT = '/var/www/project/project/web_private' # models.py from django.conf import settings @python_2_unicode_compatible class MessageFile(models.Model): """ """ fs_private_folder = FileSystemStorage(location=settings.PRIVATE_FOLDER_ROOT) message = models.ForeignKey(Message) file = models.FileField('file', storage=fs_private_folder,...

Django migrations using RunPython to commit changes

django,django-migrations
I want to alter a foreign key in one of my models that can currently have NULL values to not be nullable. I removed the null=True from my field and ran makemigrations Because I'm an altering a table that already has rows which contain NULL values in that field I...

Django 1.8 migration unable to cast column id to integer

django,postgresql,django-migrations
I'm migrating my site from an SQLite backend to a Postgres backend. We've been running native-Django style migrations (i.e., not South) from the beginning of the project. Most of the migrations run fine, but there's a hiccup in our of our applications. We got this far in the Postgres migration....

Invalid migration SQL when adding blank=True CharField in Django 1.7.8

mysql,django,django-migrations
I'm adding a not null CharField to one of my models: channel_class = models.CharField(max_length=10, blank=True) I create the migration with: django-admin.py makemigrations webapp Which asks me nothing about default values (see this ticket about default values prompting for blank=True). The SQL generated for this migration is: $ django-admin.py sqlmigrate webapp...

Custom CMSPlugin migrations in Django 1.7

django,django-cms,django-migrations
I'm using Django CMS 3.1 with Django 1.7.8. I'm trying to upgrade an old project to these respective versions but I'm hitting a brick wall with a couple of my custom-written CMSPlugin-inhereting plugins. Django won't migrate any models. django.db.migrations.state.InvalidBasesError: Cannot resolve bases for [..My Models..] The models are defined as...

NOT NULL constraint failed when running `migrate`

django,django-migrations
I changed my models.py file and when running migrate I get this error. The property is a OneToOneField(). I have tried adding null=True but that doesn't seem to fix it. It is also weird that even when I comment out the property and run makemigrations followed by migrate, I still...

migrate model slug field to unique for existing database

python,django,django-models,django-migrations
In old database slug field was not unique, so duplicates are created. Now i want to migrate slug field unique=True. slug = models.CharField(max_length=255, unique=True) $ python manage.py migrate django.db.utils.IntegrityError: (1062, "Duplicate entry 'some-x-slug' for key 'some_model_slug_6c7ae6ae040a5e98_uniq'") is it possible when migrating if django detects duplicate slug, i want to add...

Django alterField does not preserve NOT NULL when modifying max_length

mysql,sql,django,django-models,django-migrations
I'm writing a django migration to change the max_length on CharField in the following model from 200 to 255, but doing so changes these fields from non-nullable to nullable. I want these fields to remain non-nullable. With sqlmigrate I can see the sql that django runs for each migration: Model...

Deleting unused Models, stale content types prompt

django,django-migrations
I am removing an unnecessary table and model from our Django website. I have removed all foriegn key references before the migrations.DeleteModel(...) is called, but I still am receiving the following prompt when I run the migration: The following content types are stale and need to be deleted: myapp |...

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

django,django-migrations,django-1.8
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...

Revert Django 1.7 RemoveField migration

django,django-south,django-1.7,django-migrations
If I have a non-nullable model field, remove it, and create a migration, that migration becomes non-reversible: Consider the following model: class Foo(models.Model): bar = models.TextField() test = models.TextField() # This field is to go away, bye-bye! And migration: # app/migrations/003_remove_foo_test.py class Migration(migrations.Migration): dependencies = [ ('app', '0002_foo_test'), ] operations...