django-migrations

Django 1.8.4 makemigrations CreateModel changes field's order

坚强是说给别人听的谎言 提交于 2019-12-25 06:39:08
问题 We've just switched to Django 1.8.4 (from 1.6, so first time using migrations), and we've noticed an issue when using the makemigrations command. The issue happens when creating a new model that contains Foreign Keys. The command generates a migration file with the field order changed: it sets all the FKs last, and reorganizes them by alphabetical order. Here's an example : class AnotherRandomModel(models.Model): attr1 = models.FloatField() class AnotherRandomModel2(models.Model): attr1 =

django handwritten migrations altering auth

我们两清 提交于 2019-12-25 02:49:12
问题 I am using django 1.8.1 and trying to extend the length of auth_user name field from one of my apps. Before, with south, I could just target the app with an underscore like so: db.alter_column('auth_group', 'name', models.CharField(max_length=120, null=False, blank=False)) However, in django 1.8, I don't see a way to do this as django putts the app name in the sql withing the source code. I don't want to edit django source code so I have no way of changing that. my current attemp is here:

Django 1.7.1 requires a Default value for field - but no entry is in database. Why?

拥有回忆 提交于 2019-12-24 03:14:58
问题 I ran into a strange problem. I'm using Django 1.7.1 on Mac OS X Yosemite and I have configured a local MySQL database. Normally, I create a model and if I want to add another field, I just do a ./manage.py migrate and Django creates a new database column. I did exactly that. Here's my model: from django.db import models from django.utils.translation import ugettext as _ class Product(models.Model): CATEGORY_CHOICES = ( ('apphosting', _('Application Hosting')), ('webhosting', _('Web Hosting')

Why GenericRelation fields does not work in Data Migrations(Django)

寵の児 提交于 2019-12-24 02:25:19
问题 I want to make data migration in order to add user read post in database. There is such code: def user_read_posts(apps, schema_editor): User = apps.get_model("main", "User") Post = apps.get_model("main", "Post") Comment = apps.get_model("comments", "Comment") comments = Comment.objects.all() for comment in comments: print (comment.content_object.__class__.__name__) if isinstance(comment.content_object, Post): comment.user.read_posts.add(comment.content_object) class Migration(migrations

Prepopulate database with fixtures or with script?

你说的曾经没有我的故事 提交于 2019-12-24 00:24:45
问题 I'm not an expert but I think is a good idea using a Class to define choices and to prepopulate the database with these choices. I think that make easier to change choices, etc So in my models.py I have: class City(models.Model): name = models.CharField(max_length=32) distance = models.SmallIntegerField(blank=True, null=True) #etc class OtherClass(models.Model): name = models.CharField(max_length=32) #etc class UserProfile(models.Model): name = models.CharField(max_length=32) city = models

No such column error in Django models

五迷三道 提交于 2019-12-23 18:01:49
问题 I'm adding a new field to my Django model, but no matter what the new field is, I get a no such column error when I try to run makemigrations File "/Users/hugokitano/canopy/lib/python2.7/site-packages/django/db/backends/sqlite3/base.py", line 318, in execute return Database.Cursor.execute(self, query, params) django.db.utils.OperationalError: no such column: stats_control.con_LD_file Here's what my code for the model looks like now. If the commented field is uncommented, it will fail the

Django Polls Tutorial No changes detected in app polls

元气小坏坏 提交于 2019-12-23 13:39:09
问题 I'm going through the Django Polls tutorial, and I'm trying the command "python manage.py makemigrations polls", and I keep getting the message "No changes detected in app 'polls'" I don't understand what I'm doing wrong or how I could do it differently, or what the message even means. EDIT for clarity: I expect something somewhat like the printout on the tutorial: Migrations for 'polls': 0001_initial.py: - Create model Question - Create model Choice And then later in the tutorial, when it

Adding indexes to model fields in Django with migrations

十年热恋 提交于 2019-12-23 07:20:09
问题 I am trying to add indexes on model fields using Field.db_index for an app that has migrations. Looking at Django's documentation all I need to do is to set db_index=True : class Person(models.Model): first_name = models.CharField() last_name = models.CharField(db_index=True) and then I first tried the new Django's Migration: ./manage.py makemigrations app-name but Migration does not seem to notice the change and does not add the sql command for creating an index. So I tried django-admin.py

Django manage.py: Migration applied before its dependency

别等时光非礼了梦想. 提交于 2019-12-23 06:48:09
问题 When running python manage.py migrate I encounter this error: django.db.migrations.exceptions.InconsistentMigrationHistory: Migration <appname>.0016_auto_<date2>_<time2> is applied before its dependency <appname>.0001_squashed_0015_auto_<date1>_<time1> running showmigrations returns: <appname> [X] 0001_squashed_0015_auto_<date1>_<time1> (15 squashed migrations) [X] 0016_auto_<date2>_<time2> [ ] 0017_<modelname>_squashed_0019_auto_<date3>_<time3> (3 squashed migrations) I was trying out django

Django 1.7 makemigrations freezing/hanging

北战南征 提交于 2019-12-22 03:51:45
问题 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