I have a problem, to solve it I tried going into the shell but I couldn't find out the solution so I hope that you can help me. I'm importing my Model Images which contains an id and the image URL but I can't get it because of this error. The code:
from recipes_database.models import Images
Images.objects.all()
And here the error:
Traceback (most recent call last): File "F:\Developement\Projects\WhatToCookWeb\venv\lib\site-packages\django\db\backends\utils.py", line 84, in _execute
return self.cursor.execute(sql, params) File "F:\Developement\Projects\WhatToCookWeb\venv\lib\site-packages\django\db\backends\sqlite3\base.py", line 413, in execute
return Database.Cursor.execute(self, query, params) sqlite3.OperationalError: no such column: Images.id
The above exception was the direct cause of the following exception:
Traceback (most recent call last): File "<console>", line 1, in <module> File "F:\Developement\Projects\WhatToCookWeb\venv\lib\site-packages\django\db\models\query.py", line 263, in __repr__
data = list(self[:REPR_OUTPUT_SIZE + 1]) File "F:\Developement\Projects\WhatToCookWeb\venv\lib\site-packages\django\db\models\query.py", line 269, in __len__
self._fetch_all() File "F:\Developement\Projects\WhatToCookWeb\venv\lib\site-packages\django\db\models\query.py", line 1303, in _fetch_all
self._result_cache = list(self._iterable_class(self)) File "F:\Developement\Projects\WhatToCookWeb\venv\lib\site-packages\django\db\models\query.py", line 53, in __iter__
results = compiler.execute_sql(chunked_fetch=self.chunked_fetch, chunk_size=self.chunk_size) File "F:\Developement\Projects\WhatToCookWeb\venv\lib\site-packages\django\db\models\sql\compiler.py", line 1154, in execute_sql
cursor.execute(sql, params) File "F:\Developement\Projects\WhatToCookWeb\venv\lib\site-packages\django\db\backends\utils.py", line 98, in execute
return super().execute(sql, params) File "F:\Developement\Projects\WhatToCookWeb\venv\lib\site-packages\django\db\backends\utils.py", line 66, in execute
return self._execute_with_wrappers(sql, params, many=False, executor=self._execute) File "F:\Developement\Projects\WhatToCookWeb\venv\lib\site-packages\django\db\backends\utils.py", line 75, in _execute_with_wrappers
return executor(sql, params, many, context) File "F:\Developement\Projects\WhatToCookWeb\venv\lib\site-packages\django\db\backends\utils.py", line 84, in _execute
return self.cursor.execute(sql, params) File "F:\Developement\Projects\WhatToCookWeb\venv\lib\site-packages\django\db\utils.py", line 90, in __exit__
raise dj_exc_value.with_traceback(traceback) from exc_value File "F:\Developement\Projects\WhatToCookWeb\venv\lib\site-packages\django\db\backends\utils.py", line 84, in _execute
return self.cursor.execute(sql, params) File "F:\Developement\Projects\WhatToCookWeb\venv\lib\site-packages\django\db\backends\sqlite3\base.py", line 413, in execute
return Database.Cursor.execute(self, query, params) django.db.utils.OperationalError: no such column: Images.id
But when I do the same thing with my other models it works and I am wondering whats different this time. Here is my Images Model:
class Images(models.Model):
# Field name made lowercase.
rezept_id = models.ForeignKey(
'Rezepte', models.DO_NOTHING, db_column='Rezept_ID', blank=True, null=True)
# Field name made lowercase.
image_url = models.CharField(
db_column='Image_URL', blank=True, null=True, max_length=1000)
class Meta:
managed = False
db_table = 'Images'
I think that Django somehow uses a wrong query because there is no Images.id just an Images.recipe_id. Hope you can help me Thank you!
recipe_idthePRIMARY KEY? What is the primary key of this table?