Reputation: 55
I have a simple model class as below
class Language(models.Model):
name= models.CharField(max_length=20)
code= models.CharField(max_length=5)
status=models.BooleanField()
create_at=models.DateTimeField(auto_now_add=True)
update_at=models.DateTimeField(auto_now=True)
def __str__(self):
return self.name
and I want to use it like this
llist = Language.objects.filter()
list1 = []
for rs in llist:
list1.append((rs.code,rs.name))
langlist = (list1)
but it keeps throwing this error when I try to use llist
:
return Database.Cursor.execute(self, query, params)
django.db.utils.OperationalError: no such table: home_language
I tried to use python manage.py shell
to make queries and it's showing the same above error.
This is the full error :
Traceback (most recent call last):
File "C:\Users\Daisy\Downloads\Django-E-Commerce-master\env\lib\site-packages\django\db\backends\utils.py", line 86, in _execute
return self.cursor.execute(sql, params)
File "C:\Users\Daisy\Downloads\Django-E-Commerce-master\env\lib\site-packages\django\db\backends\sqlite3\base.py", line 396, in execute
return Database.Cursor.execute(self, query, params)
sqlite3.OperationalError: no such table: home_language
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "manage.py", line 21, in <module>
main()
File "manage.py", line 17, in main
execute_from_command_line(sys.argv)
File "C:\Users\Daisy\Downloads\Django-E-Commerce-master\env\lib\site-packages\django\core\management\__init__.py", line 401, in execute_from_command_line
utility.execute()
File "C:\Users\Daisy\Downloads\Django-E-Commerce-master\env\lib\site-packages\django\core\management\__init__.py", line 377, in execute
django.setup()
File "C:\Users\Daisy\Downloads\Django-E-Commerce-master\env\lib\site-packages\django\__init__.py", line 24, in setup
apps.populate(settings.INSTALLED_APPS)
File "C:\Users\Daisy\Downloads\Django-E-Commerce-master\env\lib\site-packages\django\apps\registry.py", line 114, in populate
app_config.import_models()
File "C:\Users\Daisy\Downloads\Django-E-Commerce-master\env\lib\site-packages\django\apps\config.py", line 211, in import_models
self.models_module = import_module(models_module_name)
File "c:\users\daisy\appdata\local\programs\python\python38\lib\importlib\__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
File "<frozen importlib._bootstrap>", line 991, in _find_and_load
File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 783, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "C:\Users\Daisy\OneDrive\Documents\Work\django\prjs\funnystore\mysite\home\models.py", line 29, in <module>
for rs in llist:
File "C:\Users\Daisy\Downloads\Django-E-Commerce-master\env\lib\site-packages\django\db\models\query.py", line 276, in __iter__
self._fetch_all()
File "C:\Users\Daisy\Downloads\Django-E-Commerce-master\env\lib\site-packages\django\db\models\query.py", line 1261, in _fetch_all
self._result_cache = list(self._iterable_class(self))
File "C:\Users\Daisy\Downloads\Django-E-Commerce-master\env\lib\site-packages\django\db\models\query.py", line 57, in __iter__
results = compiler.execute_sql(chunked_fetch=self.chunked_fetch, chunk_size=self.chunk_size)
File "C:\Users\Daisy\Downloads\Django-E-Commerce-master\env\lib\site-packages\django\db\models\sql\compiler.py", line 1152, in execute_sql
cursor.execute(sql, params)
File "C:\Users\Daisy\Downloads\Django-E-Commerce-master\env\lib\site-packages\django\db\backends\utils.py", line 100, in execute
return super().execute(sql, params)
File "C:\Users\Daisy\Downloads\Django-E-Commerce-master\env\lib\site-packages\django\db\backends\utils.py", line 68, in execute
return self._execute_with_wrappers(sql, params, many=False, executor=self._execute)
File "C:\Users\Daisy\Downloads\Django-E-Commerce-master\env\lib\site-packages\django\db\backends\utils.py", line 77, in _execute_with_wrappers
return executor(sql, params, many, context)
File "C:\Users\Daisy\Downloads\Django-E-Commerce-master\env\lib\site-packages\django\db\backends\utils.py", line 86, in _execute
return self.cursor.execute(sql, params)
File "C:\Users\Daisy\Downloads\Django-E-Commerce-master\env\lib\site-packages\django\db\utils.py", line 90, in __exit__
raise dj_exc_value.with_traceback(traceback) from exc_value
File "C:\Users\Daisy\Downloads\Django-E-Commerce-master\env\lib\site-packages\django\db\backends\utils.py", line 86, in _execute
return self.cursor.execute(sql, params)
File "C:\Users\Daisy\Downloads\Django-E-Commerce-master\env\lib\site-packages\django\db\backends\sqlite3\base.py", line 396, in execute
return Database.Cursor.execute(self, query, params)
django.db.utils.OperationalError: no such table: home_language
Upvotes: 1
Views: 10735
Reputation: 1
For me this works
python3 manage.py makemigrations
python3 manage.py migrate
Upvotes: -1
Reputation: 1
You can delete the SQLite db and files in the migration folder and then run the command
python manage.py makemigrations <your name app>
and then python manage.py migrate.
python manage.py makemigrations (your app name)
python manage.py migrate
Upvotes: -1
Reputation: 53
I used the migration for the specific app, in your case it's:
python3 manage.py makemigrations home
python3 manage.py migrate
Upvotes: 1
Reputation: 66
In my case the Error was solved with removing data through your admin panel in advance. Then:
python manage.py makemigrations
python manage.py migrate
Upvotes: 0
Reputation: 41
use this code on your command prompt:
python manage.py migrate --run-syncdb
this worked for me........
Upvotes: 4
Reputation: 25
Delete this model (home_language) from all of your codes if you used it in any condition, and then migrate it:
python3 manage.py makemigrations
python3 manage.py migrate
i hope it should work.
Upvotes: -1
Reputation: 166
You should make migrations and migrate the database using:
python manage.py makemigrations
python manage.py migrate
Upvotes: 0