django-migrations

How to add django-mptt rebuild to migration?

点点圈 提交于 2019-12-12 12:44:09
问题 I have add the django-mptt to existing database, and create the new migration. Migration process was asked for default values for level , left , right and such fields, but doesn't add the model.rebuild operation to migration file. How to add rebuild operation to migration file manually? 回答1: Try the following: from __future__ import unicode_literals from django.db import migrations from mptt import register, managers def rebuild_tree(apps, schema_editor): YourMPTTModel = apps.get_model('your

ResetDjango postgresql database? flush does not work

一个人想着一个人 提交于 2019-12-12 05:26:00
问题 I have made changes to my model and tried to migrate the database using: python3 manage.py makemigrations python3 manage.py migrate I got the following output: vagrant@vagrant-ubuntu-trusty-64:/vagrant/grader$ python3 manage.py makemigrations No changes detected vagrant@vagrant-ubuntu-trusty-64:/vagrant/grader$ python3 manage.py migrate Operations to perform: Apply all migrations: contenttypes, sessions, admin, auth, core Running migrations: Rendering model states... DONE Applying core.0002

Can't get rid of “nonexistent parent node” in django 1.11

无人久伴 提交于 2019-12-12 04:47:29
问题 So far I've tried about anything the internet has given me on this problem and I still haven't solved it. Python 3.6.1 - django 1.11.2 - virtualenv I had a django project with two apps account and app2 . Recently I decided to split them up into more appropriate apps as the project is growing. Now I have a total of 8 apps where account got split up into user_auth and user , then I deleted account . To tidy it up even more I moved all apps from the root folder to /apps/ . So far, only user,

Django use two databases for seamless updates

两盒软妹~` 提交于 2019-12-12 03:07:18
问题 I have a database (PostgreSQL), which I need to update from time to time (every 6 hours). I don't want partial updates to appear on the output, so my idea is: We use two databases, let them be named prod and update . prod is all the time on duty, while update is being updated every 6 hours and then it should pass changes (or change places) to (with) prod . How can I implement such behaviour in Django? I know, that there are migrations and db_to_write, db_to_read variants, but they stay not

Django: How to migrate primary key to BigIntegerField of class that inherits from AbstractUser

。_饼干妹妹 提交于 2019-12-12 02:18:19
问题 I have a Django project that has numerous applications. Each application has a models.py file. I'm using this strategy to modify all the models in my project such that their primary keys are explicitly defined as id = models.BigIntegerField(primary_key=True) instead of implicitly defined as id = models.IntegerField(primary_key=True) This strategy is working well for most of my models. Except there is a problem with one model. It is my Profile model defined below: class Profile(CachingMixin,

Should Django Migration (makemigrations) commited separately than creating model?

混江龙づ霸主 提交于 2019-12-11 17:55:39
问题 It's vague for me which strategy is better in Version controlling of django or any other web framework: Commit separately for creating model and running makemigrations . Commit both tasks together. I think myself first strategy is better, because of migration files which creating after running makemigrations . But I need to be sure which one in better. Is there any certain standard for this? 回答1: Both the strategies you list can work. But option one is better. You can commit Django Migration

How to let existing entries empty when using auto_now_add?

陌路散爱 提交于 2019-12-11 17:12:37
问题 I added a field to my existing model : creation_date = models.DateTimeField( auto_now_add=True, blank=True, null=True) The resulting file after makemigrations looks like migrations.AddField( model_name='document', name='creation_date', field=models.DateTimeField(auto_now_add=True, null=True), ), When applying the migration, auto_now_add is applied to all existing entries. How to avoid that ? creation_date must remain null for all data recorded before the migration is applied. 回答1: The easiest

Django 1.8 creates migration but nothing has changed

大城市里の小女人 提交于 2019-12-11 12:38:30
问题 I am having a migration issue with a Django 1.8.2 application. I'm using two models, Product and Fee . Product recently had a change to its unique_together field. Fee had no changes to its unique_together field. When I run ./manage.py makemigrations I get a file with two changes: operations = [ migrations.AlterUniqueTogether( name='fee', unique_together=set([('product', 'fee_type', 'content_type', 'object_id', 'activation_date')]), ), migrations.AlterUniqueTogether( name='product', unique

Migrate data from original User model to Custom User model in django 1.8

喜欢而已 提交于 2019-12-11 12:12:35
问题 I am created a custom user model. There were already have users in the auth database. So, I using the data migration to migrate the data to my custom user model. This is how I did the data migration in the auto migration file (which I found from here): UPDATED from __future__ import unicode_literals from django.db import models, migrations class Migration(migrations.Migration): dependencies = [ ('userauth', '0002_auto_20150721_0605'), ] operations = [ migrations.RunSQL('INSERT INTO userauth

Moving Wagtail pages in a migration

只谈情不闲聊 提交于 2019-12-11 07:07:13
问题 I'm restructuring my Wagtail app to remove an IndexPage that only has a single item in it, and moving that item to be a child of the current IndexPage's parent. basically moving from this: Page--| |--IndexPage--| |--ChildPages (there's only ever 1 of these) to this: Page--| |--ChildPage I've made the changes to the models so that this structure is used for creating new content and fixed the relevant views to point to the ChildPage directly. But now I want to migrate the current data to the