django-migrations

Django 1.7 migration cannot find app

China☆狼群 提交于 2019-12-21 17:55:40
问题 I'm creating a data migration for app Notification , in here i'm using the reference of model, Manager , from app accounts Manager = apps.get_model("accounts", "Manager") It throws error : self.code(from_state.render(), schema_editor) File "/home/notifications/migrations/0004_auto_20150720_0127.py", line 12, in set_notification_setttings Manager = apps.get_model("accounts", "Manager") File "/home/local/lib/python2.7/site-packages/django/apps/registry.py", line 202, in get_model return self

Migrating from django user model to a custom user model

陌路散爱 提交于 2019-12-20 18:35:09
问题 I am following these two references (one and two) to have a custom user model in order to authenticate via email and also to add an extra field to it. class User(AbstractBaseUser, PermissionsMixin): email = models.EmailField( unique=True, max_length=254, ) mobile_number = models.IntegerField(unique=True) is_active = models.BooleanField(default=True) is_admin = models.BooleanField(default=False) objects = UserManager() ... ... class Meta: db_table = 'auth_user' ... ... As you can see, I have

Add non-null and unique field with already populated model

不问归期 提交于 2019-12-20 17:26:58
问题 I have one model in my app running in a server with a few entries. I need to add a SlugField , unique and not-null for this model. The SlugField will be populated based on trading_name . I've changed my model in order to add this new field and modified save method: class Supplier(StatusModel): SLUG_MAX_LENGTH = 210 slug = models.SlugField(unique=True, max_length=SLUG_MAX_LENGTH) trading_name = models.CharField(max_length=200, verbose_name=_('trading name')) ... def save(self, *args, **kwargs)

Django Programming error column does not exist even after running migrations

坚强是说给别人听的谎言 提交于 2019-12-17 23:35:35
问题 I run python manage.py makemigrations and I get: No changes detected Then, python manage.py migrate and I get: No migrations to apply. Then, I try to push the changes to production: git push heroku master Everything up-to-date Then, in production, I repeat the command: heroku run python manage.py migrate No migrations to apply. Just in case, I run makemigrations in production: heroku run python manage.py makemigrations No changes detected WHY then I get a ProgrammingError at .... column ....

Django Migrations Add Field with Default as Function of Model

和自甴很熟 提交于 2019-12-17 23:03:56
问题 I added a new, non-nullable field to my Django model and am trying to use migrations to deploy that change. How would I set default value to use for existing models to be some function of those models rather than a constant? As an example let's say I previously had a created_on field and I just added an updated_on field whose value I want to set initially to the model's created_on . How would I do this in a migration? This is what I am trying to start with: migrations.AddField( model_name=

Migration clashes with forms.py

♀尐吖头ヾ 提交于 2019-12-17 20:11:36
问题 The command python manage.py makemigrations fails most of time due to the forms.py , in which new models or new fields are referenced at class definition level. So I have to comment each such definitions for the migration to operate. It's a painfull task. I don't understand why the migration process import the forms.py module. I think that importing models modules should be sufficient. Is there a way to avoid those errors ? 回答1: I was having this same issue and found the specific problem.

Django migrations RunPython not able to call model methods

痴心易碎 提交于 2019-12-17 17:54:38
问题 I'm creating a data migration using the RunPython method. However when I try to run a method on the object none are defined. Is it possible to call a method defined on a model using RunPython ? 回答1: Model methods are not available in migrations, including data migrations. However there is workaround, which should be quite similar to calling model methods. You can define functions inside migrations that mimic those model methods you want to use. If you had this method: class Order(models.Model

How to migrate back from initial migration in Django 1.7?

China☆狼群 提交于 2019-12-17 17:53:00
问题 I created a new app with some models and now I noticed that some of the models are poorly thought out. As I haven't committed the code the sensible thing would be to migrate the database to last good state and redo the migration with better models. In this case the last good state is database where the new app doesn't exist. How can I migrate back from initial migration in Django 1.7? In South one could do: python manage.py migrate <app> zero Which would clear <app> from migration history and

Disable migrations when running unit tests in Django 1.7

青春壹個敷衍的年華 提交于 2019-12-17 17:33:49
问题 Django 1.7 introduced database migrations. When running the unit tests in Django 1.7, it forces a migrate , that takes a long time. So I would like to skip the django migrations, and create the database in the final state. I know that ignoring the migrations can be a bad practice, as that part of the code would not be tested. But that's not the case: I'm running the full migrations in the CI test server (jenkins). I only want to skip the migrations in my local tests, where the speed matters.

Django - makemigrations - No changes detected

笑着哭i 提交于 2019-12-17 17:25:31
问题 I was trying to create migrations within an existing app using the makemigrations command but it outputs "No changes detected". Usually I create new apps using the startapp command but did not use it for this app when I created it. After debugging, I found that it is not creating migration because the migrations package/folder is missing from an app. Would it be better if it creates the folder if it is not there or am I missing something? 回答1: To create initial migrations for an app, run