Column core_event.hometask does not exist - django

When I run my Django project on production server, I have this error:
ProgrammingError at /admin/core/event/
column core_event.hometask does not exist
LINE 1: ..._event"."is_approved", "core_event"."event_type", "core_even...
What I should do to fix it? Now I haven't "hometask" field in my model:
class Event(models.Model):
name = models.CharField(max_length=100, null=True)
author = models.ForeignKey(User, on_delete=models.CASCADE, null=True)
description = models.TextField(max_length=1000, blank=True, null=True)
date_start = models.DateTimeField(null=True, blank=True)
date_finish = models.DateTimeField(null=True, blank=True)
image = models.ImageField(
upload_to="event_images/", default='event_images/default.png', blank=True, null=True)
is_approved = models.BooleanField(null=True)
TYPE_CHOICES = (
('Event', "Мероприятие"),
('Lesson', "Урок"),
)
event_type = models.CharField(choices=TYPE_CHOICES, max_length=200, default="Мероприятие")
topics = ArrayField(models.CharField(max_length=200), blank=True, null=True)
materials = ArrayField(models.URLField(), blank=True, null=True)
possible_users = models.ManyToManyField("core.User", blank=True, related_name='possible_users')
actual_users = models.ManyToManyField("core.User", blank=True, related_name='actual_users')
classes = models.ManyToManyField("core.Class", blank=True, related_name='classes')

From what you posted, looks like the field existed in the model before but not anymore. However, your admin.py still has reference to the old field of hometask.
So, go to admin.py, search for hometask, and remove it.

Related

It is not possible to migrate a new user element to the django table

I am faced with the problem that it is not possible to migrate the new user value to the database table. At first there were errors on related_name, but I fixed it, and now that this value cannot be zero, at the same time, if I write that null=True, then the user cannot be displayed in the records in the future.
class Writehelp(models.Model):
users = models.ForeignKey(User,on_delete = models.CASCADE,related_name='helpedman',null=False,verbose_name='Автор')
titles = models.CharField(max_length=200, verbose_name='Заголовок', blank=True)
descriptions = models.TextField(blank=True, verbose_name='Описание')
createdtimes = models.DateField(auto_now_add=True, db_index=True, verbose_name='Дата создания')
prices = models.DecimalField(max_digits=10, decimal_places=2, null=True, blank=True, verbose_name='Цена')
course = models.IntegerField(null=True, blank=True, verbose_name='Курс')
semestr = models.IntegerField(null=True, blank=True, verbose_name='Семестр')
subjects = models.CharField(max_length=200, null=True, blank=True, verbose_name='Предмет')
institutes = models.CharField(max_length=200, null=True, blank=True, verbose_name='Институт')
However, when I migrated this model, there were no problems:
class UploadFile(models.Model):
user = models.ForeignKey(User,on_delete = models.CASCADE,related_name='file_created' ,verbose_name='Автор')
title = models.CharField(max_length=200, verbose_name='Заголовок',blank=True)
# uploadedfile = models.FileField(upload_to='files/',null=True, verbose_name='Файл')
description = models.TextField(blank=True, verbose_name='Описание')
createdtime = models.DateField(auto_now_add=True, db_index=True, verbose_name='Дата создания')
price = models.DecimalField(max_digits=10, decimal_places=2, null=True, blank=True, verbose_name='Цена')
number_course = models.IntegerField(null=True, blank=True, verbose_name='Курс')
number_semestr = models.IntegerField(null=True, blank=True, verbose_name='Семестр')
subjectt = models.CharField(max_length=200, null=True,blank=True,verbose_name='Предмет')
type_materials = models.CharField(max_length=200,null=True,blank=True, verbose_name='Тип работы')
institute = models.CharField(max_length=200, null=True,blank=True, verbose_name='Институт')
Add defult=None to uploadedfile field in your UploadFile model.

Can`t manually delete record from sqlite table, because related table with __old does not exists

I want to manually delete records from sqlite table(witch was created with Django 1.10, Table from i want to delete records called main.storage_claim, it has relation to main.storage_claimlist), but got error: Error deleting record: no such table: main.storage_claimlist__old.
I dont know why it want this table.
I have only main.storage_claimlist without __old.
Btw, i`m using DB Browser for SQLite as gui tool for working with sqlite.
Can someone explain what the heck is __old?
ClaimList model:
class ClaimList(models.Model):
""" Claim list contains one to many claim. Used for grouping claims. """
created_at = models.DateTimeField(default=datetime.now, blank=True, null=True)
from_storage = models.ForeignKey(
Storage, related_name='from_storage', blank=True, null=True, default=True)
to_storage = models.ForeignKey(
Storage, related_name='to_storage', blank=True, null=True, default=True)
status = models.CharField(max_length=255, blank=True, null=True)
separation = models.CharField(max_length=255, blank=True, null=True)
insurance_company = models.ForeignKey(
InsuranceCompany, null=True, blank=True)
patient = models.CharField(max_length=255, blank=True, null=False)
Claim model:
class Claim(models.Model):
""" Claim contain information about what need to be transefer """
medicine = models.CharField(max_length=255, blank=True, null=True)
claim_list = models.ForeignKey(ClaimList, blank=True, null=True)
requested_amount = models.DecimalField(
default=0, max_digits=5, decimal_places=0)
given_amount = models.DecimalField(
default=0, max_digits=5, decimal_places=0)
requested_unit = models.CharField(max_length=100, blank=True, null=True)
given_unit = models.CharField(max_length=100, blank=True, null=True)
from_income = models.ForeignKey(Income, blank=True, null=True)
status = models.CharField(max_length=100, blank=True, null=True)
is_will_be_accepted_in_future = models.BooleanField(default=False)
price = models.DecimalField(null=True, max_digits=10, decimal_places=5)
sum = models.DecimalField(null=True, max_digits=10, decimal_places=5)
objects = ClaimManager()

Why django inspectdb doesn't create foreign keys correctly on an existing database? [duplicate]

django=2.2.3
mariadb
This error occurs after importing model from an existing database with 'inspectdb' and changed field properties.
class Post(models.Model):
post_id = models.AutoField(primary_key=True)
post_name = models.CharField(max_length=255, blank=True, null=True)
email = models.CharField(max_length=255, blank=True, null=True)
class Rank(models.Model):
rank_id = models.AutoField(primary_key=True)
rank_type = models.IntegerField(blank=True, null=True)
created_at = models.DateTimeField()
# post_id = models.IntegerField(blank=True, null=True)
post_id = models.ForeignKey(Post, on_delete=models.SET_NULL, blank=True, null=True)
Originally, it was # post_id, but I removed "managed = False", changed it to ForeignKey and then "migrate".
As far as I know that if the "post_id" in the "Post" model is "primary_key True", it replaces the "id" value with "post_id". But "Django" keeps calling up the "post_id_id".
There is no command to refer to post_id_id elsewhere.
If you have a solution or something that I'm missing, please give me some advice.
-------Add more after commented by Daniel Roseman --------
class Post(models.Model):
post_id = models.AutoField(primary_key=True)
post_name = models.CharField(max_length=255, blank=True, null=True)
email = models.CharField(max_length=255, blank=True, null=True)
class Gallery(models.Model):
uid = models.AutoField(prymary_key=True)
gallery_name = models.CharField(...)
class Rank(models.Model):
rank_id = models.AutoField(primary_key=True)
rank_type = models.IntegerField(blank=True, null=True)
created_at = models.DateTimeField()
# post_id = models.IntegerField(blank=True, null=True)
post_id = models.ForeignKey(Post, on_delete=models.SET_NULL, blank=True, null=True)
# uid = models.IntegerField(blank=True, null=True)
uid = models.ForeignKey(Gallery, on_delete=models.SET_NULL, blank=True, null=True)
Don't call your ForeignKey post_id. Call it post. The underlying database field is post_id; Django adds the _id suffix automatically.

Make a query to django models

How is "translation" for following query to django queryset?
SELECT guid FROM feedme_feeditem
WHERE feed_id IN
(SELECT id FROM feedme_feed WHERE country_id IN
(SELECT id FROM feedme_country WHERE name='NL'))
models.py
class Country(models.Model):
name = models.CharField(max_length=250, blank=True)
class Category(models.Model):
name = models.CharField(max_length=250, blank=True)
slug = models.SlugField(blank=True, null=True, editable=False)
user = models.ForeignKey(User, blank=True, null=True)
country = models.ForeignKey(Country, blank=True, null=True)
class Feed(models.Model):
link = models.CharField(blank=True, max_length=450)
url = models.CharField(blank=True, max_length=450)
title = models.CharField(blank=True, null=True, max_length=250)
category = models.ForeignKey(Category, blank=True, null=True)
user = models.ForeignKey(User, blank=True, null=True)
last_update = models.DateField(blank=True, null=True, editable=False)
country = models.ForeignKey(Country, blank=True, null=True)
class FeedItem(models.Model):
title = models.CharField(max_length=350, blank=True)
link = models.URLField(blank=True)
content = models.TextField(blank=True)
feed = models.ForeignKey(Feed, blank=True, null=True)
read = models.BooleanField(default=False)
guid = models.CharField(max_length=255)
pub_date = models.DateTimeField()
To make more simple I already tried add country = models.ForeignKey(Country, blank=True, null=True) to FeedItem class but does't work how i expected.
guids = FeedItem.objects.filter(feed__country__name = 'NL')

forms problem in django 1.1

I have the following form:
class ModuleItemForm2(forms.ModelForm):
class Meta:
model = Module_item
fields = ('title', 'media', 'thumb', 'desc', 'default', 'player_option')
The model is:
class Module_item(models.Model):
title = models.CharField(max_length=100)
layout = models.CharField(max_length=5, choices=LAYOUTS_CHOICE)
media = models.CharField(help_text='Media url', max_length=500, blank=True, null=True)
conserv = models.ForeignKey(Conserv, help_text= 'Redirect to Conserv', blank=True, null=True)
conserve_section = models.CharField(max_length=100, help_text= 'Section within the redirected Conserv', blank=True, null=True)
parent = models.ForeignKey('self', help_text='Upper menu.', blank=True, null=True)
module = models.ForeignKey(Module, blank=True, null=True)
thumb = models.FileField(upload_to='sms/module_items/thumbs', blank=True, null=True)
desc = models.CharField(max_length=500, blank=True, null=True)
auto_play = models.IntegerField(help_text='Auto start play (miliseconds)', blank=True, null=True)
order = models.IntegerField(help_text='Display order', blank=True, null=True)
depth = models.IntegerField(help_text='The layout depth', blank=True, null=True)
flow_replace = models.IntegerField(blank=True, null=True)
default = models.IntegerField(help_text='The selected sub item (Note: Starting from 0)', blank=True, null=True)
player_options = models.CharField(max_length=1000, null=True, blank=True)
In my view I build form:
module_item_form2 = ModuleItemForm2()
print module_item_form2
And I get the following error on the print line:
'NoneType' object has no attribute 'label'
It works fine with django 1.0.2. I see the error only in django 1.1.
Do you have an idea what am I doing wrong?
Regards, Arshavski Alexander.
You have player_options in the model, but player_option in the list of form fields. Does it work if you add the s in the form fields tuple?