django-migrations

Can I use a database view as a model in Django?

馋奶兔 提交于 2019-12-17 10:34:13
问题 i'd like to use a view i've created in my database as the source for my django-view. Is this possible, without using custom sql? ******13/02/09 UPDATE*********** Like many of the answers suggest, you can just make your own view in the database and then use it within the API by defining it in models.py. some warning though: manage.py syncdb will not work anymore the view need the same thing at the start of its name as all the other models(tables) e.g if your app is called "thing" then your

How to reset migrations in Django 1.7

谁都会走 提交于 2019-12-17 10:21:46
问题 (I know there is a title the same as this, but the question is different). I have managed to get my development machine migrations and production migrations out of sync. I have a Django app which was using South. I had my own workflow that worked fine (it probably wasn't the correct way to do things, but I had no problems with it). Basically I have a script that copies the production database dump to my development machine. It also copied the migration files. That way the two were in synch,

django 1.7 migrate gets error “table already exists”

十年热恋 提交于 2019-12-17 10:19:03
问题 I am trying to apply a migration but am getting the error: django.db.utils.OperationalError: (1050, "Table 'customers_customer' already exists") I get this by issuing the following command: python manage.py migrate My customer table already exists, so what do I do to let the migration know this, not error out, and run my modification to my model? I ran this on my local environment with local database with no problem. It is when I pointed my database to production and ran migrate above that I

How to simplify migrations in Django 1.7?

╄→гoц情女王★ 提交于 2019-12-17 08:10:11
问题 There are already similar questions for South, but I have started my project with Django 1.7 and am not using South. During development a lot of migrations have been created, however the software is not yet delievered and there exists no database that must be migrated. Therefore I would like to reset the migrations as if my current model was the original one and recreate all databases. What is the recommended way to do that? EDIT: As of Django 1.8 there is a new command named squashmigrations

Django 1.7 - makemigrations not detecting changes

倾然丶 夕夏残阳落幕 提交于 2019-12-17 04:47:15
问题 As the title says, I can't seem to get migrations working. The app was originally under 1.6, so I understand that migrations won't be there initially, and indeed if I run python manage.py migrate I get: Operations to perform: Synchronize unmigrated apps: myapp Apply all migrations: admin, contenttypes, auth, sessions Synchronizing apps without migrations: Creating tables... Installing custom SQL... Installing indexes... Running migrations: No migrations to apply. If I make a change to any

Django 1.7 - makemigrations not detecting changes

折月煮酒 提交于 2019-12-17 04:47:15
问题 As the title says, I can't seem to get migrations working. The app was originally under 1.6, so I understand that migrations won't be there initially, and indeed if I run python manage.py migrate I get: Operations to perform: Synchronize unmigrated apps: myapp Apply all migrations: admin, contenttypes, auth, sessions Synchronizing apps without migrations: Creating tables... Installing custom SQL... Installing indexes... Running migrations: No migrations to apply. If I make a change to any

Django - Migrate ManyToMany to through

人走茶凉 提交于 2019-12-14 04:18:00
问题 I have a model that looks like this: class Assignment(models.Model): """An assignment covers a range of years, has multiple coders and one specific task""" title = models.CharField(blank=True, max_length=100) start_date = models.DateField(default=date.today) end_date = models.DateField(default=date.today) coders = models.ManyToManyField(User, related_name='assignments') I want to change this model (which has data already in production) so that it looks like this: class Assignment(models.Model

Django 1.8 Circular Dependecy error

核能气质少年 提交于 2019-12-13 12:47:29
问题 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 with the problem when asked to create brand new migrations from your models. In a future release of Django, squashmigrations will be updated to attempt to resolve these errors itself."

Whats the logic of importing models as `app_registry.get_model('app_name', 'ModelName')` in a custom migration

◇◆丶佛笑我妖孽 提交于 2019-12-13 04:17:32
问题 I am asking this question because I ran into this django.db.utils.IntegrityError: null value in column “lft” violates not-null constraint when I was using django-hordak which uses MPPT models. The solution provided is hacky as it violates the common practice but it works. THE BASICS In django when writing custom migrations for example when creating baseline data. def forward_func(apps_registry, schema_editor): Model = apps_registry.get_model('app_name', 'ModelName') Model.objects.create(**{

Permission denied to create migration folder in Django app in vagrant

谁说胖子不能爱 提交于 2019-12-13 01:09:24
问题 I am trying to upgrade to Django 1.8 from 1.4 I tried to run the following command in vagrant environment $ python manage.py makemigrations [app_name] and got this error Traceback (most recent call last): File "manage.py", line 9, in execute_from_command_line(sys.argv) File "/srv/www/[project]/shared/env/local/lib/python2.7/site-packages/django/core/management/ init .py", line 338, in execute_from_command_line utility.execute() File "/srv/www/[project]/shared/env/local/lib/python2.7/site