when I was trying to make migrations: python manage.py makemigrations
The following error occurred: django.db.utils.OperationalError: no such table: blog_category
Traceback (most recent call last):
File "C:\Users\injemam\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django\db\backends\utils.py", line 84, in _execute
return self.cursor.execute(sql, params)
File "C:\Users\injemam\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django \db\backends\sqlite3\base.py", line 383, in execute
return Database.Cursor.execute(self, query, params)
sqlite3.OperationalError: no such table: blog_category
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "manage.py", line 15, in <module>
execute_from_command_line(sys.argv)
File "C:\Users\injemam\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django \core\management\__init__.py", line 381, in execute_from_command_line
utility.execute()
File "C:\Users\injemam\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django\core\management\__init__.py", line 375, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "C:\Users\injemam\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django\core\management\base.py", line 323, in run_from_argv
self.execute(*args, **cmd_options)
File "C:\Users\injemam\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django\core\management\base.py", line 361, in execute
self.check()
File "C:\Users\injemam\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django\core\management\base.py", line 390, in check
include_deployment_checks=include_deployment_checks,
File "C:\Users\injemam\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django\core\management\base.py", line 377, in _run_checks
return checks.run_checks(**kwargs)
File "C:\Users\injemam\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django\core\checks\registry.py", line 72, in run_checks
new_errors = check(app_configs=app_configs)
File "C:\Users\injemam\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django\core\checks\urls.py", line 40, in check_url_namespaces_unique
all_namespaces = _load_all_namespaces(resolver)
File "C:\Users\injemam\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django\core\checks\urls.py", line 57, in _load_all_namespaces
url_patterns = getattr(resolver, 'url_patterns', [])
File "C:\Users\injemam\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django\utils\functional.py", line 80, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "C:\Users\injemam\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django\urls\resolvers.py", line 571, in url_patterns
patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
File "C:\Users\injemam\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django\utils\functional.py", line 80, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "C:\Users\injemam\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django\urls\resolvers.py", line 564, in urlconf_module
return import_module(self.urlconf_name)
File "C:\Users\injemam\AppData\Local\Programs\Python\Python37-32\lib\importlib\__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
File "<frozen importlib._bootstrap>", line 983, in _find_and_load
File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 728, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "C:\xampp\htdocs\Django project\blooper\Bona-Blog-master\bona_blog\urls.py", line 27, in <module>
path('', include('blog.urls', namespace='blog')), # Urls for article app.
File "C:\Users\injemam\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django\urls\conf.py", line 34, in include
urlconf_module = import_module(urlconf_module)
File "C:\Users\injemam\AppData\Local\Programs\Python\Python37-32\lib\importlib\__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
File "<frozen importlib._bootstrap>", line 983, in _find_and_load
File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 728, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "C:\xampp\htdocs\Django project\blooper\Bona-Blog-master\blog\urls.py", line 5, in <module>
from blog.views.blog.article_views import (
File "C:\xampp\htdocs\Django project\blooper\Bona-Blog-master\blog\views\blog\article_views.py", line 25, in <module>
from blog.forms.blog.article_forms import (
File "C:\xampp\htdocs\Django project\blooper\Bona-Blog-master\blog\forms\blog\article_forms.py", line 16, in <module>
class ArticleCreateForm(forms.ModelForm):
File "C:\xampp\htdocs\Django project\blooper\Bona-Blog-master\blog\forms\blog\article_forms.py", line 18, in ArticleCreateForm
class Meta:
File "C:\xampp\htdocs\Django project\blooper\Bona-Blog-master\blog\forms\blog\article_forms.py", line 47, in Meta
"data-live-search": "true"
File "C:\Users\injemam\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django\forms\widgets.py", line 562, in __init__
self.choices = list(choices)
File "C:\Users\injemam\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django\db\models\query.py", line 274, in __iter__
self._fetch_all()
File "C:\Users\injemam\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django\db\models\query.py", line 1242, in _fetch_all
self._result_cache = list(self._iterable_class(self))
File "C:\Users\injemam\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django\db\models\query.py", line 55, in __iter__
results = compiler.execute_sql(chunked_fetch=self.chunked_fetch, chunk_size=self.chunk_size)
File "C:\Users\injemam\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django\db\models\sql\compiler.py", line 1097, in execute_sql
cursor.execute(sql, params)
File "C:\Users\injemam\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django\db\backends\utils.py", line 99, in execute
return super().execute(sql, params)
File "C:\Users\injemam\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django\db\backends\utils.py", line 67, in execute
return self._execute_with_wrappers(sql, params, many=False, executor=self._execute)
File "C:\Users\injemam\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django\db\backends\utils.py", line 76, in _execute_with_wrappers
return executor(sql, params, many, context)
File "C:\Users\injemam\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django\db\backends\utils.py", line 84, in _execute
return self.cursor.execute(sql, params)
File "C:\Users\injemam\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django\db\utils.py", line 89, in __exit__
raise dj_exc_value.with_traceback(traceback) from exc_value
File "C:\Users\injemam\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django\db\backends\utils.py", line 84, in _execute
return self.cursor.execute(sql, params)
File "C:\Users\injemam\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django\db\backends\sqlite3\base.py", line 383, in execute
return Database.Cursor.execute(self, query, params)
django.db.utils.OperationalError: no such table: blog_category
Please Help How to remove this error?
I'm new in Django and I had clone this project from Github
https://github.com/Williano/Bona-Blog
using Django-2.2
Apparantly,
Either you have changed your db tables manually (e.g. via db interface)
You are missing one or more of required migration files.
As you are on a development environment I would suggest
drop the db
re-create the db
then python manage.py migrate again
This seams to be a bug in the blog software.
When the migrations are created the models in the code are introspected and in this process many modules are imported with the models. In the software there is a point where a query is made at import time (article_forms.py, line 40. At this point the table the query points to does not exist yet and it fails.
It is possible the author did not notice the bug because he/she had the table already when doing the change. And he/she never created a new instance from scratch.
You should report it as a bug.
Since you are in development stage you can drop the db and recreate it. But before recreating delete all the previous migration files on all the apps. Make sure that there are only lnlt files in those folders
python manage.py makemigrations
python manage.py migrate
This fixed it for me!
This question is old but I am putting a solution that worked for me as no one else has mentioned it yet. Also this could have just been a comment but I need 50 reputations to pull a comment, which I do not have at the time of writing this.
Instead of running project-wide migrations, make it specific to the blog app:
python manage.py makemigrations blog
python manage.py migrate blog
Do this for your other apps.
Related
I am trying to split my django settings into production and development. Th ebiggest question that I have is how to use two different databases for the two environments? How to deal with migrations?
I tried changing the settings for the development server to use a new empty database, however, I can not apply the migrations to create the tables that I already have in the production database.
All the guides on multiple databases focus on the aspect of having different types of data in different databases (such as users database, etc.) but not the way I am looking for.
Could you offer some insights about what the best practices are and how to manage the two databases also in terms of migrations?
EDIT:
Here is what I get when I try to run python manage.py migrate on the new database:
Traceback (most recent call last):
File "/opt/homebrew/Caskroom/miniforge/base/envs/stokk/lib/python3.9/site-packages/django/db/backends/utils.py", line 85, in _execute
return self.cursor.execute(sql, params)
psycopg2.errors.UndefinedTable: relation "dashboard_posttags" does not exist
LINE 1: ...ags"."tag", "dashboard_posttags"."hex_color" FROM "dashboard...
^
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/....../manage.py", line 22, in <module>
main()
File "/....../manage.py", line 18, in main
execute_from_command_line(sys.argv)
File "/opt/homebrew/Caskroom/miniforge/base/envs/stokk/lib/python3.9/site-packages/django/core/management/__init__.py", line 425, in execute_from_command_line
utility.execute()
File "/opt/homebrew/Caskroom/miniforge/base/envs/stokk/lib/python3.9/site-packages/django/core/management/__init__.py", line 419, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/opt/homebrew/Caskroom/miniforge/base/envs/stokk/lib/python3.9/site-packages/django/core/management/base.py", line 373, in run_from_argv
self.execute(*args, **cmd_options)
File "/opt/homebrew/Caskroom/miniforge/base/envs/stokk/lib/python3.9/site-packages/django/core/management/base.py", line 417, in execute
output = self.handle(*args, **options)
File "/opt/homebrew/Caskroom/miniforge/base/envs/stokk/lib/python3.9/site-packages/django/core/management/base.py", line 90, in wrapped
res = handle_func(*args, **kwargs)
File "/opt/homebrew/Caskroom/miniforge/base/envs/stokk/lib/python3.9/site-packages/django/core/management/commands/migrate.py", line 75, in handle
self.check(databases=[database])
File "/opt/homebrew/Caskroom/miniforge/base/envs/stokk/lib/python3.9/site-packages/django/core/management/base.py", line 438, in check
all_issues = checks.run_checks(
File "/opt/homebrew/Caskroom/miniforge/base/envs/stokk/lib/python3.9/site-packages/django/core/checks/registry.py", line 77, in run_checks
new_errors = check(app_configs=app_configs, databases=databases)
File "/opt/homebrew/Caskroom/miniforge/base/envs/stokk/lib/python3.9/site-packages/django/core/checks/urls.py", line 13, in check_url_config
return check_resolver(resolver)
File "/opt/homebrew/Caskroom/miniforge/base/envs/stokk/lib/python3.9/site-packages/django/core/checks/urls.py", line 23, in check_resolver
return check_method()
File "/opt/homebrew/Caskroom/miniforge/base/envs/stokk/lib/python3.9/site-packages/django/urls/resolvers.py", line 446, in check
for pattern in self.url_patterns:
File "/opt/homebrew/Caskroom/miniforge/base/envs/stokk/lib/python3.9/site-packages/django/utils/functional.py", line 48, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "/opt/homebrew/Caskroom/miniforge/base/envs/stokk/lib/python3.9/site-packages/django/urls/resolvers.py", line 632, in url_patterns
patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
File "/opt/homebrew/Caskroom/miniforge/base/envs/stokk/lib/python3.9/site-packages/django/utils/functional.py", line 48, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "/opt/homebrew/Caskroom/miniforge/base/envs/stokk/lib/python3.9/site-packages/django/urls/resolvers.py", line 625, in urlconf_module
return import_module(self.urlconf_name)
File "/opt/homebrew/Caskroom/miniforge/base/envs/stokk/lib/python3.9/importlib/__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 850, in exec_module
File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
File "/....../app/urls.py", line 11, in <module>
from main_platform.views.investor import AccountView, profile, app_home_redirect
File "/....../main_platform/views/investor.py", line 118, in <module>
class PostFilter(django_filters.FilterSet):
File "/....../main_platform/views/investor.py", line 124, in PostFilter
for tag in PostTags.objects.all():
File "/opt/homebrew/Caskroom/miniforge/base/envs/stokk/lib/python3.9/site-packages/django/db/models/query.py", line 280, in __iter__
self._fetch_all()
File "/opt/homebrew/Caskroom/miniforge/base/envs/stokk/lib/python3.9/site-packages/auto_prefetch/__init__.py", line 98, in _fetch_all
super()._fetch_all()
File "/opt/homebrew/Caskroom/miniforge/base/envs/stokk/lib/python3.9/site-packages/django/db/models/query.py", line 1354, in _fetch_all
self._result_cache = list(self._iterable_class(self))
File "/opt/homebrew/Caskroom/miniforge/base/envs/stokk/lib/python3.9/site-packages/django/db/models/query.py", line 51, in __iter__
results = compiler.execute_sql(chunked_fetch=self.chunked_fetch, chunk_size=self.chunk_size)
File "/opt/homebrew/Caskroom/miniforge/base/envs/stokk/lib/python3.9/site-packages/django/db/models/sql/compiler.py", line 1202, in execute_sql
cursor.execute(sql, params)
File "/opt/homebrew/Caskroom/miniforge/base/envs/stokk/lib/python3.9/site-packages/django/db/backends/utils.py", line 99, in execute
return super().execute(sql, params)
File "/opt/homebrew/Caskroom/miniforge/base/envs/stokk/lib/python3.9/site-packages/sentry_sdk/integrations/django/__init__.py", line 563, in execute
return real_execute(self, sql, params)
File "/opt/homebrew/Caskroom/miniforge/base/envs/stokk/lib/python3.9/site-packages/django/db/backends/utils.py", line 67, in execute
return self._execute_with_wrappers(sql, params, many=False, executor=self._execute)
File "/opt/homebrew/Caskroom/miniforge/base/envs/stokk/lib/python3.9/site-packages/django/db/backends/utils.py", line 76, in _execute_with_wrappers
return executor(sql, params, many, context)
File "/opt/homebrew/Caskroom/miniforge/base/envs/stokk/lib/python3.9/site-packages/django/db/backends/utils.py", line 85, in _execute
return self.cursor.execute(sql, params)
File "/opt/homebrew/Caskroom/miniforge/base/envs/stokk/lib/python3.9/site-packages/django/db/utils.py", line 90, in __exit__
raise dj_exc_value.with_traceback(traceback) from exc_value
File "/opt/homebrew/Caskroom/miniforge/base/envs/stokk/lib/python3.9/site-packages/django/db/backends/utils.py", line 85, in _execute
return self.cursor.execute(sql, params)
django.db.utils.ProgrammingError: relation "dashboard_posttags" does not exist
LINE 1: ...ags"."tag", "dashboard_posttags"."hex_color" FROM "dashboard...
If you have a new empty database, you can just run "python manage.py migrate" and all migrations will be executed on the new database. The already done migrations will be stored in a table in that database so that django always "remembers" the migrations state of each individual database. Of course that new database will only have the tables structure - there is not yet any data copied!
Does this answer your question?
Found the solution in this post
Apparently, Django tries to evaluate all queries declared on class level before running the migration. This causes an error because the database is empty, and the query can not run.
To solve this, comment out everything in the main urls.py, so that there are no imports and urlpatterns. Then run python manage.py makemigrations and after it has completed, revert the urls.py to the original.
In my django project, python manage.py runserver runs extremely slowly. To check where the problem is I run python -v manage.py check. This shows that it's getting stuck on:
# C:\Users\mvren\miniconda3\envs\dataenv\lib\__pycache__\_strptime.cpython-39.pyc matches C:\Users\mvren\miniconda3\envs\dataenv\lib\_strptime.py
# code object from 'C:\\Users\\mvren\\miniconda3\\envs\\dataenv\\lib\\__pycache__\\_strptime.cpython-39.pyc'
import '_strptime' # <_frozen_importlib_external.SourceFileLoader object at 0x000002084418A670>
When I delete _strptime.py from my env, it runs smoothly. But then my app doesn't work. Specifically, I get the following traceback:
File "C:\Users\mvren\miniconda3\envs\dataenv\lib\threading.py", line 954, in _bootstrap_inner
self.run()
File "C:\Users\mvren\miniconda3\envs\dataenv\lib\threading.py", line 892, in run
self._target(*self._args, **self._kwargs)
File "C:\Users\mvren\miniconda3\envs\dataenv\lib\site-packages\django\utils\autoreload.py", line 64, in wrapper
fn(*args, **kwargs)
File "C:\Users\mvren\miniconda3\envs\dataenv\lib\site-packages\django\core\management\commands\runserver.py", line 118, in inner_run
self.check(display_num_errors=True)
File "C:\Users\mvren\miniconda3\envs\dataenv\lib\site-packages\django\core\management\base.py", line 419, in check
all_issues = checks.run_checks(
File "C:\Users\mvren\miniconda3\envs\dataenv\lib\site-packages\django\core\checks\registry.py", line 76, in run_checks
new_errors = check(app_configs=app_configs, databases=databases)
File "C:\Users\mvren\miniconda3\envs\dataenv\lib\site-packages\django\core\checks\urls.py", line 13, in check_url_config
return check_resolver(resolver)
File "C:\Users\mvren\miniconda3\envs\dataenv\lib\site-packages\django\core\checks\urls.py", line 23, in check_resolver
return check_method()
File "C:\Users\mvren\miniconda3\envs\dataenv\lib\site-packages\django\urls\resolvers.py", line 412, in check
for pattern in self.url_patterns:
File "C:\Users\mvren\miniconda3\envs\dataenv\lib\site-packages\django\utils\functional.py", line 48, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "C:\Users\mvren\miniconda3\envs\dataenv\lib\site-packages\django\urls\resolvers.py", line 598, in url_patterns
patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
File "C:\Users\mvren\miniconda3\envs\dataenv\lib\site-packages\django\utils\functional.py", line 48, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "C:\Users\mvren\miniconda3\envs\dataenv\lib\site-packages\django\urls\resolvers.py", line 591, in urlconf_module
return import_module(self.urlconf_name)
File "C:\Users\mvren\miniconda3\envs\dataenv\lib\importlib\__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 855, in exec_module
File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
File "C:\Users\mvren\OneDrive\Documents\Coding\datanz\datasite_old\datasite\urls.py", line 20, in <module>
from . import views
File "C:\Users\mvren\OneDrive\Documents\Coding\datanz\datasite_old\datasite\views.py", line 2, in <module>
from data.dash_lab import ur_latest
File "C:\Users\mvren\OneDrive\Documents\Coding\datanz\datasite_old\data\dash_lab.py", line 28, in <module>
df_lab['qpc'] = df_lab.groupby('Series_reference').Data_value.pct_change()
File "C:\Users\mvren\miniconda3\envs\dataenv\lib\site-packages\pandas\core\frame.py", line 3634, in __setitem__
indexer = convert_to_index_sliceable(self, key)
File "C:\Users\mvren\miniconda3\envs\dataenv\lib\site-packages\pandas\core\indexing.py", line 2336, in convert_to_index_sliceable
res = idx._get_string_slice(str(key))
File "C:\Users\mvren\miniconda3\envs\dataenv\lib\site-packages\pandas\core\indexes\datetimelike.py", line 236, in _get_string_slice
parsed, reso = self._parse_with_reso(key)
File "C:\Users\mvren\miniconda3\envs\dataenv\lib\site-packages\pandas\core\indexes\datetimelike.py", line 231, in _parse_with_reso
parsed, reso_str = parsing.parse_time_string(label, self.freq)
File "pandas\_libs\tslibs\parsing.pyx", line 321, in pandas._libs.tslibs.parsing.parse_time_string
File "pandas\_libs\tslibs\parsing.pyx", line 355, in pandas._libs.tslibs.parsing.parse_datetime_string_with_reso
File "pandas\_libs\tslibs\parsing.pyx", line 509, in pandas._libs.tslibs.parsing._parse_dateabbr_string
ModuleNotFoundError: No module named '_strptime'
I don't really understand, because I'm not using 'strptime anywhere? How can I solve this?
are you using a virtual environment?
if yes try to delete the virtual env , and create a new environment and install all the packages.
Or change the python version python3.10 or python3.8 and create virtual environment on python3.8 or python3.10
There are a lot of similar posts to this but none that I have found seem to resolve the program. I have tried to add a field to a custom user model that inherits from Django's AbstractUser:
class AppUser(AbstractUser):
credibility_rating = models.FloatField(default=0)
When I save this and try to run python manage.py makemigrations it gives me this error:
Traceback (most recent call last):
File "/Users/jhcscomputer1/.local/share/virtualenvs/senior_project-hOu14Mps/lib/python3.10/site-packages/django/db/backends/utils.py", line 89, in _execute
return self.cursor.execute(sql, params)
psycopg2.errors.UndefinedColumn: column api_appuser.credibility_rating does not exist
LINE 1: ...ppuser"."is_active", "api_appuser"."date_joined", "api_appus...
When I replace the field credibility_rating with pass the error goes away. Similarly, when I try to add a new field in a different model, the error doesn't occur either. I am not sure if this matters, but I am using Postgres. My settings.py file does include AUTH_USER_MODEL = "api.AppUser" where api is the name of my app. I am not sure where I am going wrong. Thank you for any help.
Full traceback:
Traceback (most recent call last):
File "/Users/jhcscomputer1/.local/share/virtualenvs/senior_project-hOu14Mps/lib/python3.10/site-packages/django/db/backends/utils.py", line 89, in _execute
return self.cursor.execute(sql, params)
psycopg2.errors.UndefinedColumn: column api_appuser.credibility_rating does not exist
LINE 1: ...ppuser"."is_active", "api_appuser"."date_joined", "api_appus...
^
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/Users/jhcscomputer1/Desktop/senior_project/senior_project/manage.py", line 22, in <module>
main()
File "/Users/jhcscomputer1/Desktop/senior_project/senior_project/manage.py", line 18, in main
execute_from_command_line(sys.argv)
File "/Users/jhcscomputer1/.local/share/virtualenvs/senior_project-hOu14Mps/lib/python3.10/site-packages/django/core/management/__init__.py", line 446, in execute_from_command_line
utility.execute()
File "/Users/jhcscomputer1/.local/share/virtualenvs/senior_project-hOu14Mps/lib/python3.10/site-packages/django/core/management/__init__.py", line 440, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/Users/jhcscomputer1/.local/share/virtualenvs/senior_project-hOu14Mps/lib/python3.10/site-packages/django/core/management/base.py", line 414, in run_from_argv
self.execute(*args, **cmd_options)
File "/Users/jhcscomputer1/.local/share/virtualenvs/senior_project-hOu14Mps/lib/python3.10/site-packages/django/core/management/base.py", line 455, in execute
self.check()
File "/Users/jhcscomputer1/.local/share/virtualenvs/senior_project-hOu14Mps/lib/python3.10/site-packages/django/core/management/base.py", line 487, in check
all_issues = checks.run_checks(
File "/Users/jhcscomputer1/.local/share/virtualenvs/senior_project-hOu14Mps/lib/python3.10/site-packages/django/core/checks/registry.py", line 88, in run_checks
new_errors = check(app_configs=app_configs, databases=databases)
File "/Users/jhcscomputer1/.local/share/virtualenvs/senior_project-hOu14Mps/lib/python3.10/site-packages/django/core/checks/urls.py", line 14, in check_url_config
return check_resolver(resolver)
File "/Users/jhcscomputer1/.local/share/virtualenvs/senior_project-hOu14Mps/lib/python3.10/site-packages/django/core/checks/urls.py", line 24, in check_resolver
return check_method()
File "/Users/jhcscomputer1/.local/share/virtualenvs/senior_project-hOu14Mps/lib/python3.10/site-packages/django/urls/resolvers.py", line 480, in check
for pattern in self.url_patterns:
File "/Users/jhcscomputer1/.local/share/virtualenvs/senior_project-hOu14Mps/lib/python3.10/site-packages/django/utils/functional.py", line 49, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "/Users/jhcscomputer1/.local/share/virtualenvs/senior_project-hOu14Mps/lib/python3.10/site-packages/django/urls/resolvers.py", line 696, in url_patterns
patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
File "/Users/jhcscomputer1/.local/share/virtualenvs/senior_project-hOu14Mps/lib/python3.10/site-packages/django/utils/functional.py", line 49, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "/Users/jhcscomputer1/.local/share/virtualenvs/senior_project-hOu14Mps/lib/python3.10/site-packages/django/urls/resolvers.py", line 689, in urlconf_module
return import_module(self.urlconf_name)
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 883, in exec_module
File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
File "/Users/jhcscomputer1/Desktop/senior_project/senior_project/senior_project/urls.py", line 21, in <module>
path('api/', include('api.urls'))
File "/Users/jhcscomputer1/.local/share/virtualenvs/senior_project-hOu14Mps/lib/python3.10/site-packages/django/urls/conf.py", line 38, in include
urlconf_module = import_module(urlconf_module)
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 883, in exec_module
File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
File "/Users/jhcscomputer1/Desktop/senior_project/senior_project/api/urls.py", line 2, in <module>
from . import views
File "/Users/jhcscomputer1/Desktop/senior_project/senior_project/api/views.py", line 21, in <module>
for user in AppUser.objects.all():
File "/Users/jhcscomputer1/.local/share/virtualenvs/senior_project-hOu14Mps/lib/python3.10/site-packages/django/db/models/query.py", line 320, in __iter__
self._fetch_all()
File "/Users/jhcscomputer1/.local/share/virtualenvs/senior_project-hOu14Mps/lib/python3.10/site-packages/django/db/models/query.py", line 1507, in _fetch_all
self._result_cache = list(self._iterable_class(self))
File "/Users/jhcscomputer1/.local/share/virtualenvs/senior_project-hOu14Mps/lib/python3.10/site-packages/django/db/models/query.py", line 57, in __iter__
results = compiler.execute_sql(
File "/Users/jhcscomputer1/.local/share/virtualenvs/senior_project-hOu14Mps/lib/python3.10/site-packages/django/db/models/sql/compiler.py", line 1361, in execute_sql
cursor.execute(sql, params)
File "/Users/jhcscomputer1/.local/share/virtualenvs/senior_project-hOu14Mps/lib/python3.10/site-packages/django/db/backends/utils.py", line 103, in execute
return super().execute(sql, params)
File "/Users/jhcscomputer1/.local/share/virtualenvs/senior_project-hOu14Mps/lib/python3.10/site-packages/django/db/backends/utils.py", line 67, in execute
return self._execute_with_wrappers(
File "/Users/jhcscomputer1/.local/share/virtualenvs/senior_project-hOu14Mps/lib/python3.10/site-packages/django/db/backends/utils.py", line 80, in _execute_with_wrappers
return executor(sql, params, many, context)
File "/Users/jhcscomputer1/.local/share/virtualenvs/senior_project-hOu14Mps/lib/python3.10/site-packages/django/db/backends/utils.py", line 84, in _execute
with self.db.wrap_database_errors:
File "/Users/jhcscomputer1/.local/share/virtualenvs/senior_project-hOu14Mps/lib/python3.10/site-packages/django/db/utils.py", line 91, in __exit__
raise dj_exc_value.with_traceback(traceback) from exc_value
File "/Users/jhcscomputer1/.local/share/virtualenvs/senior_project-hOu14Mps/lib/python3.10/site-packages/django/db/backends/utils.py", line 89, in _execute
return self.cursor.execute(sql, params)
django.db.utils.ProgrammingError: column api_appuser.credibility_rating does not exist
LINE 1: ...ppuser"."is_active", "api_appuser"."date_joined", "api_appus...
hi guys i'm working in project with cms called tendenci which required to work with PostgreSQL and python django, I've been working on it on a virtual machine with Ubuntu and when i tried to migrate to production server (with Ubuntu also) i faced a lot of issues the last is migrate the db, actually i did all the required steps but it still showing an error when i try to run the server
this is the command that i run
python manage.py runserver
this is the error that i get
Unhandled exception in thread started by <function check_errors.<locals>.wrapper at 0x7fadbc707a60>
Traceback (most recent call last):
File "/srv/mysite/lib/python3.6/site-packages/django/db/backends/utils.py", line 64, in execute
return self.cursor.execute(sql, params)
psycopg2.ProgrammingError: relation "site_settings_setting" does not exist
LINE 1: SELECT (1) AS "a" FROM "site_settings_setting" WHERE ("site_...
^
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/srv/mysite/lib/python3.6/site-packages/django/utils/autoreload.py", line 228, in wrapper
fn(*args, **kwargs)
File "/srv/mysite/lib/python3.6/site-packages/django/core/management/commands/runserver.py", line 124, in inner_run
self.check(display_num_errors=True)
File "/srv/mysite/lib/python3.6/site-packages/django/core/management/base.py", line 359, in check
include_deployment_checks=include_deployment_checks,
File "/srv/mysite/lib/python3.6/site-packages/django/core/management/base.py", line 346, in _run_checks
return checks.run_checks(**kwargs)
File "/srv/mysite/lib/python3.6/site-packages/django/core/checks/registry.py", line 81, in run_checks
new_errors = check(app_configs=app_configs)
File "/srv/mysite/lib/python3.6/site-packages/django/core/checks/urls.py", line 16, in check_url_config
return check_resolver(resolver)
File "/srv/mysite/lib/python3.6/site-packages/django/core/checks/urls.py", line 26, in check_resolver
return check_method()
File "/srv/mysite/lib/python3.6/site-packages/django/urls/resolvers.py", line 256, in check
for pattern in self.url_patterns:
File "/srv/mysite/lib/python3.6/site-packages/django/utils/functional.py", line 35, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "/srv/mysite/lib/python3.6/site-packages/django/urls/resolvers.py", line 407, in url_patterns
patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
File "/srv/mysite/lib/python3.6/site-packages/django/utils/functional.py", line 35, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "/srv/mysite/lib/python3.6/site-packages/django/urls/resolvers.py", line 400, in urlconf_module
return import_module(self.urlconf_name)
File "/srv/mysite/lib/python3.6/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 994, in _gcd_import
File "<frozen importlib._bootstrap>", line 971, in _find_and_load
File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 665, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 678, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "/var/www/clients/client1/web1/web/mysite/conf/urls.py", line 6, in <module>
from tendenci.urls import handler500 # noqa: F401
File "/srv/mysite/lib/python3.6/site-packages/tendenci/urls.py", line 18, in <module>
registry_autodiscover()
File "/srv/mysite/lib/python3.6/site-packages/tendenci/apps/registry/register.py", line 21, in autodiscover
import_module('%s.app_registry' % app)
File "/srv/mysite/lib/python3.6/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "/srv/mysite/lib/python3.6/site-packages/tendenci/apps/entities/app_registry.py", line 18, in <module>
site.register(Entity, EntityRegistry)
File "/srv/mysite/lib/python3.6/site-packages/tendenci/apps/registry/sites.py", line 157, in register
cache_reg_apps(self.get_registered_apps())
File "/srv/mysite/lib/python3.6/site-packages/tendenci/apps/registry/sites.py", line 177, in get_registered_apps
apps = RegisteredApps(self._registry)
File "/srv/mysite/lib/python3.6/site-packages/tendenci/apps/registry/sites.py", line 44, in __init__
if check_setting(*setting_tuple):
File "/srv/mysite/lib/python3.6/site-packages/tendenci/apps/site_settings/utils.py", line 156, in check_setting
scope_category=scope_category, name=name).exists()
File "/srv/mysite/lib/python3.6/site-packages/django/db/models/query.py", line 673, in exists
return self.query.has_results(using=self.db)
File "/srv/mysite/lib/python3.6/site-packages/django/db/models/sql/query.py", line 517, in has_results
return compiler.has_results()
File "/srv/mysite/lib/python3.6/site-packages/django/db/models/sql/compiler.py", line 858, in has_results
return bool(self.execute_sql(SINGLE))
File "/srv/mysite/lib/python3.6/site-packages/django/db/models/sql/compiler.py", line 899, in execute_sql
raise original_exception
File "/srv/mysite/lib/python3.6/site-packages/django/db/models/sql/compiler.py", line 889, in execute_sql
cursor.execute(sql, params)
File "/srv/mysite/lib/python3.6/site-packages/django/db/backends/utils.py", line 79, in execute
return super(CursorDebugWrapper, self).execute(sql, params)
File "/srv/mysite/lib/python3.6/site-packages/django/db/backends/utils.py", line 64, in execute
return self.cursor.execute(sql, params)
File "/srv/mysite/lib/python3.6/site-packages/django/db/utils.py", line 94, in __exit__
six.reraise(dj_exc_type, dj_exc_value, traceback)
File "/srv/mysite/lib/python3.6/site-packages/django/utils/six.py", line 685, in reraise
raise value.with_traceback(tb)
File "/srv/mysite/lib/python3.6/site-packages/django/db/backends/utils.py", line 64, in execute
return self.cursor.execute(sql, params)
django.db.utils.ProgrammingError: relation "site_settings_setting" does not exist
LINE 1: SELECT (1) AS "a" FROM "site_settings_setting" WHERE ("site_...
i don't know if there is a problem with the db or there is somthing else
Hey I am attempting to initialize a new database, but I am running into some issues setting up the migrations. The error I am getting appears to stem from setting up my forms. In a form I am using, I am creating a choice field as so:
from django import forms
from ..custom_admin import widgets, choices
class MemberForm(forms.Form):
provinces = forms.ChoiceField(label='Provinces', choices=choices.PROVINCE_CHOICES, required=True)
where PROVINCE_CHOICES comes from here:
from ..base.models import ProvinceCode
PROVINCE_CHOICES = []
for province in ProvinceCode.objects.filter(country_code_id=1).order_by('code'):
PROVINCE_CHOICES.append((province.code, province.code))
The issue seems to be that this loop is being called before the migrations occur, giving me an error stating that the Province model does not exist. Commenting out the reference to this file allows the migrations to work, however, that seems like an impractical solution for continued use. Is there a way to get around this error?
For reference, here is the error I get when I run manage.py makemigrations:
./manage.py makemigrations
Traceback (most recent call last):
File "/Users/js/Documents/VirtualEnvironments/pcenv/lib/python3.5/site-packages/django/db/backends/utils.py", line 64, in execute
return self.cursor.execute(sql, params)
psycopg2.ProgrammingError: relation "pc_psr_code" does not exist
LINE 1: ...escription", "pc_psr_code"."country_code_id" FROM "pc_psr_co...
^
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "./manage.py", line 9, in <module>
django.setup()
File "/Users/js/Documents/VirtualEnvironments/pcenv/lib/python3.5/site-packages/django/__init__.py", line 18, in setup
apps.populate(settings.INSTALLED_APPS)
File "/Users/js/Documents/VirtualEnvironments/pcenv/lib/python3.5/site-packages/django/apps/registry.py", line 115, in populate
app_config.ready()
File "/Users/js/Documents/VirtualEnvironments/pcenv/lib/python3.5/site-packages/debug_toolbar/apps.py", line 15, in ready
dt_settings.patch_all()
File "/Users/js/Documents/VirtualEnvironments/pcenv/lib/python3.5/site-packages/debug_toolbar/settings.py", line 228, in patch_all
patch_root_urlconf()
File "/Users/js/Documents/VirtualEnvironments/pcenv/lib/python3.5/site-packages/debug_toolbar/settings.py", line 216, in patch_root_urlconf
reverse('djdt:render_panel')
File "/Users/js/Documents/VirtualEnvironments/pcenv/lib/python3.5/site-packages/django/core/urlresolvers.py", line 568, in reverse
app_list = resolver.app_dict[ns]
File "/Users/js/Documents/VirtualEnvironments/pcenv/lib/python3.5/site-packages/django/core/urlresolvers.py", line 360, in app_dict
self._populate()
File "/Users/js/Documents/VirtualEnvironments/pcenv/lib/python3.5/site-packages/django/core/urlresolvers.py", line 293, in _populate
for pattern in reversed(self.url_patterns):
File "/Users/js/Documents/VirtualEnvironments/pcenv/lib/python3.5/site-packages/django/utils/functional.py", line 33, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "/Users/js/Documents/VirtualEnvironments/pcenv/lib/python3.5/site-packages/django/core/urlresolvers.py", line 417, in url_patterns
patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
File "/Users/js/Documents/VirtualEnvironments/pcenv/lib/python3.5/site-packages/django/utils/functional.py", line 33, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "/Users/js/Documents/VirtualEnvironments/pcenv/lib/python3.5/site-packages/django/core/urlresolvers.py", line 410, in urlconf_module
return import_module(self.urlconf_name)
File "/Users/js/Documents/VirtualEnvironments/pcenv/lib/python3.5/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 986, in _gcd_import
File "<frozen importlib._bootstrap>", line 969, in _find_and_load
File "<frozen importlib._bootstrap>", line 958, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 673, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 662, in exec_module
File "<frozen importlib._bootstrap>", line 222, in _call_with_frames_removed
File "/Users/js/Documents/app/platform/test/pc/urls.py", line 7, in <module>
from .custom_admin import urls as custom_urls
File "/Users/js/Documents/app/platform/test/pc/custom_admin/urls.py", line 3, in <module>
from ..party import views as party_views
File "/Users/js/Documents/app/platform/test/pc/party/views.py", line 1, in <module>
from ..party import forms
File "/Users/js/Documents/app/platform/test/pc/party/forms.py", line 2, in <module>
from ..custom_admin import widgets, choices
File "/Users/js/Documents/app/platform/test/pc/custom_admin/choices.py", line 9, in <module>
for province in ProvinceCode.objects.filter(country_code_id=1).order_by('code'):
File "/Users/js/Documents/VirtualEnvironments/pcenv/lib/python3.5/site-packages/django/db/models/query.py", line 258, in __iter__
self._fetch_all()
File "/Users/js/Documents/VirtualEnvironments/pcenv/lib/python3.5/site-packages/django/db/models/query.py", line 1074, in _fetch_all
self._result_cache = list(self.iterator())
File "/Users/js/Documents/VirtualEnvironments/pcenv/lib/python3.5/site-packages/django/db/models/query.py", line 52, in __iter__
results = compiler.execute_sql()
File "/Users/js/Documents/VirtualEnvironments/pcenv/lib/python3.5/site-packages/django/db/models/sql/compiler.py", line 848, in execute_sql
cursor.execute(sql, params)
File "/Users/js/Documents/VirtualEnvironments/pcenv/lib/python3.5/site-packages/django/db/backends/utils.py", line 79, in execute
return super(CursorDebugWrapper, self).execute(sql, params)
File "/Users/js/Documents/VirtualEnvironments/pcenv/lib/python3.5/site-packages/django/db/backends/utils.py", line 64, in execute
return self.cursor.execute(sql, params)
File "/Users/js/Documents/VirtualEnvironments/pcenv/lib/python3.5/site-packages/django/db/utils.py", line 95, in __exit__
six.reraise(dj_exc_type, dj_exc_value, traceback)
File "/Users/js/Documents/VirtualEnvironments/pcenv/lib/python3.5/site-packages/django/utils/six.py", line 685, in reraise
raise value.with_traceback(tb)
File "/Users/js/Documents/VirtualEnvironments/pcenv/lib/python3.5/site-packages/django/db/backends/utils.py", line 64, in execute
return self.cursor.execute(sql, params)
django.db.utils.ProgrammingError: relation "pc_psr_code" does not exist
LINE 1: ...escription", "pc_psr_code"."country_code_id" FROM "pc_psr_co...
Province model:
class ProvinceCode(models.Model):
code = models.CharField(blank=False, null=False, unique=True)
country_code = models.ForeignKey('CountryCode', blank=False, null=True)
You cannot execute queries during the initialization of the app registry. Your choices.py file is indirectly imported during this time, resulting in the error. To fix this issue, you can pass a callable to choices:
def get_provinces():
province_choices = []
for province in ProvinceCode.objects.filter(country_code_id=1).order_by('code'):
province_choices.append((province.code, province.code))
return province_choices
class MemberForm(forms.Form):
provinces = forms.ChoiceField(label='Provinces', choices=get_provinces, required=True)