django-migrations

python manage.py migrate does not make any changes in the postgres database

≡放荡痞女 提交于 2019-12-05 11:58:17
This seems like a simple problem I am not sure what I am doing wrong. If for example I wanted to add a new field in one of my classes in models.py by changing: class FeedBack(models.Model): feedback = models.CharField(max_length=600) user = models.ForeignKey(User,default="") to class FeedBack(models.Model): feedback = models.CharField(max_length=600) email = models.CharField(max_length=100) user = models.ForeignKey(User,default="") then I run python manage.py makemigrations python manage.py migrate and everything seems fine, but no changes have actually been made in the database. When trying

Django migrations using RunPython to commit changes

只愿长相守 提交于 2019-12-05 09:55:27
问题 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 am asked to provide a one-off value right away or edit the migration file and add a RunPython operation. My RunPython operation is listed BEFORE the AlterField operation and does the required update for this field so it doesn't

Migrations in Django 1.7

不羁岁月 提交于 2019-12-05 02:12:42
问题 I am currently involved in a project where I am using Django 1.7 development version.I want to propogate changes that I make in my models (adding a field, deleting a model, etc.) into the database schema using "makemigrations" and "migrate" commmands.I added a "age" field to one of the models in my application. country = models.CharField(max_length=50, blank=True) address = models.CharField(max_length=100, blank=True) postal_code = models.IntegerField(max_length=50, blank=True) city = models

django.core.exceptions.FieldDoesNotExist: model has no field named <function SET_NULL at 0x7fc5ae8836e0>

十年热恋 提交于 2019-12-05 01:17:16
After some googling and only finding a dead-end topic , I'm still stuck on a migration problem. My model : class CurationArticle(models.Model): title = models.CharField(max_length=150, null=True, blank=True) description = models.TextField(null=True, blank=True) link = models.CharField(max_length=255, null=True, blank=True) author = models.CharField(max_length=150, blank=True, null=True) author_link = models.CharField(max_length=255, blank=True, null=True) def __unicode__(self): return self.title The imports in the model file : from django.template.defaultfilters import date as _date import

Django 1.7 makemigrations freezing/hanging

天涯浪子 提交于 2019-12-05 00:49:55
I'm finally upgrading from Django 1.6 to 1.7, and removing South in the process. I followed the official Django instructions and removed all my old numbered migrations. Now I'm trying to run python manage.py makemigrations to get the new migrations to continue moving forward with 1.7's migrations module, but it completely hangs and the only output I get is the following: bash -cl "/Users/me/.virtualenvs/mysite-Dj17/bin/python /Applications/PyCharm.app/Contents/helpers/pycharm/django_manage.py makemigrations /Users/me/Coding/mysite" /Users/me/.virtualenvs/mysite-Dj17/lib/python2.7/site-packages

Models inside tests - Django 1.7 issue

让人想犯罪 __ 提交于 2019-12-04 23:32:02
I'm trying to port my project to use Django 1.7. Everything is fine except 1 thing. Models inside tests folders. Django 1.7 new migrations run migrate command internally. Before syncdb was ran. That means if a model is not included in migrations - it won't be populated to DB (and also to test DB). That's exactly what I'm experiencing right now. What I do is: In my /app/tests/models.py I have dummy model: class TestBaseImage(BaseImage): pass All it does is to inherit from an abstract BaseImage model. Then in tests I create instances of that dummy model to test it. The problem is that it doesn't

How to add a permission to a user/group during a django migration?

一笑奈何 提交于 2019-12-04 22:13:16
问题 I would like to execute the following migration: # -*- coding: utf-8 -*- from __future__ import unicode_literals from django.contrib.auth.models import Permission from django.db import migrations from django.conf import settings from django.contrib.auth.models import Group, User def add_api_group(apps, schema_editor): Group.objects.create(name=settings.API_USER_GROUP) # get_or_create returns a tuple, not a Group group = Group.objects.get(name=settings.API_USER_GROUP) permissions = Permission

How can I skip a migration with Django migrate command?

 ̄綄美尐妖づ 提交于 2019-12-04 16:52:28
问题 First, I am asking about Django migration introduced in 1.7, not south . Suppose I have migrations 001_add_field_x , 002_add_field_y , and both of them are applied to database. Now I change my mind and decide to revert the second migration and replace it with another migration 003_add_field_z . In other words, I want to apply 001 and 003, skipping 002, how can I do this? P.S. I know I can migrate backwards to 001, but after I make the 003 migration and execute migrate command, 001 through 003

Trying to migrate in Django 1.9 — strange SQL error “django.db.utils.OperationalError: near ”)“: syntax error”

风流意气都作罢 提交于 2019-12-04 16:43:23
问题 I don't have a clue what's causing this error. It appears to be a bug that there isn't a fix for. Could anyone tell give me a hint as to how I might get around this? It's frustrating me to no end. Thanks. Operations to perform: Apply all migrations: admin, contenttypes, optilab, auth, sessions Running migrations: Rendering model states... DONE Applying optilab.0006_auto_20160621_1640...Traceback (most recent call last): File "manage.py", line 10, in <module> execute_from_command_line(sys.argv

Django 1.7 - makemigrations creating migration for unmanaged model

喜欢而已 提交于 2019-12-04 15:46:21
问题 I am creating some dynamic Django models in my application and everything seems to be working as expected except for the migration system. If I create a dynamic Django model and set managed = False, Django's makemigrations command still generates a migration for that new model. The migration looks something like this: class Migration(migrations.Migration): dependencies = [ ('atom', '0001_initial'), ] operations = [ migrations.CreateModel( name='books', fields=[ ], options={ 'db_table': 'books