django-migrations

Django - Cannot create migrations for ImageField with dynamic upload_to value

[亡魂溺海] 提交于 2019-11-27 01:22:29
问题 I just upgraded my app to 1.7 (actually still trying). This is what i had in models.py: def path_and_rename(path): def wrapper(instance, filename): ext = filename.split('.')[-1] # set filename as random string filename = '{}.{}'.format(uuid4().hex, ext) # return the whole path to the file return os.path.join(path, filename) return wrapper class UserProfile(AbstractUser): #... avatar = models.ImageField(upload_to=path_and_rename("avatars/"), null=True, blank=True, default="avatars/none/default

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

廉价感情. 提交于 2019-11-27 00:34:47
问题 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 python manage.py makemigrations --fake core Operations to perform: Apply all migrations: core Running migrations: Rendering model states... DONE Applying core.0001_initial... FAKED Applying core

Django migration strategy for renaming a model and relationship fields

亡梦爱人 提交于 2019-11-26 23:34:17
I'm planning to rename several models in an existing Django project where there are many other models that have foreign key relationships to the models I would like to rename. I'm fairly certain this will require multiple migrations, but I'm not sure of the exact procedure. Let's say I start out with the following models within a Django app called myapp : class Foo(models.Model): name = models.CharField(unique=True, max_length=32) description = models.TextField(null=True, blank=True) class AnotherModel(models.Model): foo = models.ForeignKey(Foo) is_awesome = models.BooleanField() class

Creating Partial Indexes with Django 1.7

≯℡__Kan透↙ 提交于 2019-11-26 23:14:54
问题 The documentation for Django 1.7 mentions RunSQL classes can be used to create partial indexes on your tables. I have a table where I want the combination of title , blog & category to be unique. However if category is not provided, the combination of title & blog should still be unique. class Post(models.Model): title = models.CharField(max_length=200) blog = models.ForeignKey(Blog) category = models.ForeignKey(Category, null=True, blank=True) I can achieve this constraint with partial

Migrating ManyToManyField to null true, blank true, isn't recognized

走远了吗. 提交于 2019-11-26 23:01:35
问题 I have made a model change from standard = models.ManyToManyField(Standard) to standard = models.ManyToManyField(Standard, blank=True, null=True) South schemamigration for this app doesn't recognize the change? Similar to this question, which is unanswered: South migrations and changes to many-to-may fields 回答1: That behavior is correct: null doesn't mean anything at the database level when used with a ManyToManyField . The declaration of a ManyToManyField causes the creation of an

Django 1.7 - makemigrations not detecting changes

空扰寡人 提交于 2019-11-26 21:42:48
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 models in myapp , it still says unmigrated, as expected. But if I run python manage.py makemigrations

Django migrate --fake and --fake-initial explained

空扰寡人 提交于 2019-11-26 16:49:43
问题 I've been a user of Django for about 2 years now and there is a feature I have always been afraid of using : faking migrations . I've looked pretty much everywhere and the most information I can get is from the documentation where it states that: --fake Tells Django to mark the migrations as having been applied or unapplied, but without actually running the SQL to change your database schema. This is intended for advanced users to manipulate the current migration state directly if they’re

Django migration strategy for renaming a model and relationship fields

梦想的初衷 提交于 2019-11-26 08:44:18
问题 I\'m planning to rename several models in an existing Django project where there are many other models that have foreign key relationships to the models I would like to rename. I\'m fairly certain this will require multiple migrations, but I\'m not sure of the exact procedure. Let\'s say I start out with the following models within a Django app called myapp : class Foo(models.Model): name = models.CharField(unique=True, max_length=32) description = models.TextField(null=True, blank=True)

django revert last migration

ⅰ亾dé卋堺 提交于 2019-11-26 07:50:54
问题 I\'ve made a migration that added a new table and want to revert it and delete the migration, without creating a new migration. How do I do it? Is there a command to revert last migration and then I can simply delete the migration file? 回答1: You can revert by migrating to the previous migration. For example, if your last two migrations are: 0010_previous_migration 0011_migration_to_revert Then you would do: ./manage.py migrate my_app 0010_previous_migration You can then delete migration 0011

Django 1.8: Create initial migrations for existing schema

痞子三分冷 提交于 2019-11-26 06:11:59
问题 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 the tables EXACTLY! The best approach that I\'ve found so far was: Erase all migrations folders. Done! Delete everything from the django_migrations table. Done! Run python manage.py makemigrations --empty <app>