django-migrations

django.core.exceptions.FieldDoesNotExist: model has no field named <function SET_NULL at 0x7fc5ae8836e0>

别来无恙 提交于 2020-01-02 01:02:12
问题 After some googling and only finding a dead-end topic, I'm still stuck on a migration problem. My model : class CurationArticle(models.Model): title = models.CharField(max_length=150, null=True, blank=True) description = models.TextField(null=True, blank=True) link = models.CharField(max_length=255, null=True, blank=True) author = models.CharField(max_length=150, blank=True, null=True) author_link = models.CharField(max_length=255, blank=True, null=True) def __unicode__(self): return self

Getting a “The following content types are stale and need to be deleted” when trying to do a migrate. What does this mean, and how can I solve it?

懵懂的女人 提交于 2020-01-01 08:25:11
问题 This is my models.py: class Notification(models.Model): user = models.ForeignKey(User) createdAt = models.DateTimeField(auto_now_add=True, blank=True) read = models.BooleanField(default=False, blank=True) class Meta: abstract = True class RegularNotification(Notification): message = models.CharField(max_length=150) link = models.CharField(max_length=100) class FNotification(Notification): # same as Notification pass When I do python manage.py makemigrations , this is what it says: Migrations

django 1.7 migrations — how do I clear all migrations and start over from scratch?

落花浮王杯 提交于 2019-12-31 08:06:05
问题 So I'm rapidly iterating on a django app at the moment and I'm constantly adjusting models.py. Over the course of a day or two of programming and testing I generate a couple dozen migration files. Sometimes I really tear the schema apart and completely re-do it. This causes the migration process to complain a great deal about defaults and null values and so on. If possible, I would just like to scratch all the migration stuff and re-start the migrations now that I finally know what I'm doing.

Django migration: making a row not primary key, getting “ProgrammingError: multiple default values”?

て烟熏妆下的殇ゞ 提交于 2019-12-30 18:27:34
问题 I am working with Postgres on a Django app and I want to make a model change, resetting a row so it is no longer the primary key. This is what my model currently looks like in Django: class Meeting(TimeStampedModel): row = models.CharField(max_length=20, primary_key=True) total_items = models.IntegerField() I have run django-admin.py flush to remove all data from the database. If I run python manage.py makemigrations I see No changes detected . So we are starting from a clean base. Now I edit

How to switch the direction of a Django OneToOneField?

旧街凉风 提交于 2019-12-30 06:48:52
问题 I currently have a couple of models set up like this: from django.db import models class Child(models.Model): child_name = models.CharField(max_length=200) class Parent(models.Model): parent_name = models.CharField(max_length=200) child = models.OneToOneField(Child, null=True, blank=True) Unfortunately this is wrong, because I want a delete on the parent to cascade to the child and not vice-versa, so I really should have them set up like this: class Parent(models.Model): parent_name = models

How to switch the direction of a Django OneToOneField?

孤街醉人 提交于 2019-12-30 06:48:18
问题 I currently have a couple of models set up like this: from django.db import models class Child(models.Model): child_name = models.CharField(max_length=200) class Parent(models.Model): parent_name = models.CharField(max_length=200) child = models.OneToOneField(Child, null=True, blank=True) Unfortunately this is wrong, because I want a delete on the parent to cascade to the child and not vice-versa, so I really should have them set up like this: class Parent(models.Model): parent_name = models

How to switch the direction of a Django OneToOneField?

大憨熊 提交于 2019-12-30 06:48:15
问题 I currently have a couple of models set up like this: from django.db import models class Child(models.Model): child_name = models.CharField(max_length=200) class Parent(models.Model): parent_name = models.CharField(max_length=200) child = models.OneToOneField(Child, null=True, blank=True) Unfortunately this is wrong, because I want a delete on the parent to cascade to the child and not vice-versa, so I really should have them set up like this: class Parent(models.Model): parent_name = models

How to add through option to existing ManyToManyField with migrations and data in django

孤街醉人 提交于 2019-12-30 03:43:12
问题 I can't find reference to particular issue in docs or online. I have an existing many to many relation. class Books(models.Model): name = models.CharField(max_length=100) class Authors(models.Model): name = models.CharField(max_length=100) books = models.ManyToManyField(Books) This has migrations and data. Now I need to use through option in order to add one extra field in table holding many to many relation. class Authorship(models.Model): book = models.ForeignKey(Books) author = models

Django 1.7.1 Makemigrations fails when using lambda as default for attribute

纵饮孤独 提交于 2019-12-30 02:44:05
问题 I'm using Django 1.7.1. My model looks like this: from datetime import datetime from django.db import models class myModel(models.Model): x = models.CharField(max_length=254,null=True, blank=True,) Everything works perfectly fine. However, when I add the following attribute to myModel, it breaks: y = models.DateTimeField(default=lambda: datetime.utcnow() + timedelta(days=1), editable=False) manage.py makemigrations gives me the following error: ValueError: Cannot serialize function: lambda

Django-DB-Migrations: cannot ALTER TABLE because it has pending trigger events

血红的双手。 提交于 2019-12-28 05:08:31
问题 I want to remove null=True from a TextField: - footer=models.TextField(null=True, blank=True) + footer=models.TextField(blank=True, default='') I created a schema migration: manage.py schemamigration fooapp --auto Since some footer columns contain NULL I get this error if I run the migration: django.db.utils.IntegrityError: column "footer" contains null values I added this to the schema migration: for sender in orm['fooapp.EmailSender'].objects.filter(footer=None): sender.footer='' sender