Forums

Error while using mysql

Errors

Exception Type: ProgrammingError
Exception Value:    
(1146, "Table 'onlinecafe$cafe_db.cafe_cafename' doesn't exist")
Exception Location: /home/onlinecafe/.virtualenvs/myenv/lib/python3.7/site-packages/MySQLdb/connections.py in query, line 224

I was trying to use mysql and i get this type of error after this configuration even i have a all the table in the database.

settings

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql',
        'NAME': 'onlinecafe$cafe_db',
        'USER': 'onlinecafe',
        'PASSWORD': 'password',
        'HOST': 'onlinecafe.mysql.pythonanywhere-services.com',
    }
}

What do you see if you start a database console on your onlinecafe$cafe_db database from the databases page, then run

show tables;

...?

i did show tables; in the mysql console .It says empty set.How can i get tables

Looks like you have tables defined in your models but not migrated. Try running

python manage.py migrate

still error

What error are you getting?

Exception Type: ProgrammingError Exception Value:
(1146, "Table 'SnehaSharma05$theblog_category' doesn't exist")

.

Traceback (most recent call last):
  File "/home/SnehlataSharma05/.virtualenvs/venv/lib/python3.8/site-packages/django/db/backends/utils.py", line 84, in _execute
    return self.cursor.execute(sql, params)
  File "/home/SnehlataSharma05/.virtualenvs/venv/lib/python3.8/site-packages/django/db/backends/mysql/base.py", line 73, in execute
    return self.cursor.execute(query, args)
  File "/home/SnehlataSharma05/.virtualenvs/venv/lib/python3.8/site-packages/MySQLdb/cursors.py", line 206, in execute
    res = self._query(query)
  File "/home/SnehlataSharma05/.virtualenvs/venv/lib/python3.8/site-packages/MySQLdb/cursors.py", line 319, in _query
    db.query(q)
  File "/home/SnehlataSharma05/.virtualenvs/venv/lib/python3.8/site-packages/MySQLdb/connections.py", line 259, in query
    _mysql.connection.query(self, query)
MySQLdb._exceptions.ProgrammingError: (1146, "Table 'SnehlataSharma05$theblog.ablog_category' doesn't exist")
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 "/home/SnehlataSharma05/.virtualenvs/venv/lib/python3.8/site-packages/django/core/management/__init__.py", line 401, in execute_from_command_line
    utility.execute()
  File "/home/SnehlataSharma05/.virtualenvs/venv/lib/python3.8/site-packages/django/core/management/__init__.py", line 395, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/home/SnehlataSharma05/.virtualenvs/venv/lib/python3.8/site-packages/django/core/management/base.py", line 330, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/home/SnehlataSharma05/.virtualenvs/venv/lib/python3.8/site-packages/django/core/management/base.py", line 371, in execute
    output = self.handle(*args, **options)
  File "/home/SnehlataSharma05/.virtualenvs/venv/lib/python3.8/site-packages/django/core/management/base.py", line 85, in wrapped
    res = handle_func(*args, **kwargs)
  File "/home/SnehlataSharma05/.virtualenvs/venv/lib/python3.8/site-packages/django/core/management/commands/migrate.py", line 75, in handle
    self.check(databases=[database])
  File "/home/SnehlataSharma05/.virtualenvs/venv/lib/python3.8/site-packages/django/core/management/base.py", line 392, in check
    all_issues = checks.run_checks(
  File "/home/SnehlataSharma05/.virtualenvs/venv/lib/python3.8/site-packages/django/core/checks/registry.py", line 70, in run_checks
    new_errors = check(app_configs=app_configs, databases=databases)
  File "/home/SnehlataSharma05/.virtualenvs/venv/lib/python3.8/site-packages/django/core/checks/urls.py", line 13, in check_url_config
    return check_resolver(resolver)
  File "/home/SnehlataSharma05/.virtualenvs/venv/lib/python3.8/site-packages/django/core/checks/urls.py", line 23, in check_resolver
    return check_method()
  File "/home/SnehlataSharma05/.virtualenvs/venv/lib/python3.8/site-packages/django/urls/resolvers.py", line 408, in check
    for pattern in self.url_patterns:
  File "/home/SnehlataSharma05/.virtualenvs/venv/lib/python3.8/site-packages/django/utils/functional.py", line 48, in __get__
    res = instance.__dict__[self.name] = self.func(instance)
File "/home/SnehlataSharma05/.virtualenvs/venv/lib/python3.8/site-packages/django/urls/resolvers.py", line 589, in url_patterns
    patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
  File "/home/SnehlataSharma05/.virtualenvs/venv/lib/python3.8/site-packages/django/utils/functional.py", line 48, in __get__
    res = instance.__dict__[self.name] = self.func(instance)
  File "/home/SnehlataSharma05/.virtualenvs/venv/lib/python3.8/site-packages/django/urls/resolvers.py", line 582, in urlconf_module
    return import_module(self.urlconf_name)
  File "/home/SnehlataSharma05/.virtualenvs/venv/lib/python3.8/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 "/home/SnehlataSharma05/blog/blog/urls.py", line 24, in <module>
    path('', include('ablog.urls')),
  File "/home/SnehlataSharma05/.virtualenvs/venv/lib/python3.8/site-packages/django/urls/conf.py", line 34, in include
    urlconf_module = import_module(urlconf_module)
  File "/home/SnehlataSharma05/.virtualenvs/venv/lib/python3.8/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 "/home/SnehlataSharma05/blog/ablog/urls.py", line 2, in <module>
    from . import views
  File "/home/SnehlataSharma05/blog/ablog/views.py", line 4, in <module>
    from .forms import PostForm, EditForm, CommentForm, AddCategoryForm
  File "/home/SnehlataSharma05/blog/ablog/forms.py", line 11, in <module>
    for item in cats:
  File "/home/SnehlataSharma05/.virtualenvs/venv/lib/python3.8/site-packages/django/db/models/query.py", line 287, in __iter__
    self._fetch_all()
  File "/home/SnehlataSharma05/.virtualenvs/venv/lib/python3.8/site-packages/django/db/models/query.py", line 1308, in _fetch_all
    self._result_cache = list(self._iterable_class(self))
  File "/home/SnehlataSharma05/.virtualenvs/venv/lib/python3.8/site-packages/django/db/models/query.py", line 142, in __iter__
    return compiler.results_iter(tuple_expected=True, chunked_fetch=self.chunked_fetch, chunk_size=self.chunk_size)
  File "/home/SnehlataSharma05/.virtualenvs/venv/lib/python3.8/site-packages/django/db/models/sql/compiler.py", line 1108, in results_iter
    results = self.execute_sql(MULTI, chunked_fetch=chunked_fetch, chunk_size=chunk_size)
  File "/home/SnehlataSharma05/.virtualenvs/venv/lib/python3.8/site-packages/django/db/models/sql/compiler.py", line 1156, in execute_sql
    cursor.execute(sql, params)
  File "/home/SnehlataSharma05/.virtualenvs/venv/lib/python3.8/site-packages/django/db/backends/utils.py", line 98, in execute
    return super().execute(sql, params)
  File "/home/SnehlataSharma05/.virtualenvs/venv/lib/python3.8/site-packages/django/db/backends/utils.py", line 66, in execute
    return self._execute_with_wrappers(sql, params, many=False, executor=self._execute)
  File "/home/SnehlataSharma05/.virtualenvs/venv/lib/python3.8/site-packages/django/db/backends/utils.py", line 75, in _execute_with_wrappers
    return executor(sql, params, many, context)
  File "/home/SnehlataSharma05/.virtualenvs/venv/lib/python3.8/site-packages/django/db/backends/utils.py", line 84, in _execute
    return self.cursor.execute(sql, params)
  File "/home/SnehlataSharma05/.virtualenvs/venv/lib/python3.8/site-packages/django/db/utils.py", line 90, in __exit__
    raise dj_exc_value.with_traceback(traceback) from exc_value
  File "/home/SnehlataSharma05/.virtualenvs/venv/lib/python3.8/site-packages/django/db/backends/utils.py", line 84, in _execute
    return self.cursor.execute(sql, params)
  File "/home/SnehlataSharma05/.virtualenvs/venv/lib/python3.8/site-packages/django/db/backends/mysql/base.py", line 73, in execute
    return self.cursor.execute(query, args)
  File "/home/SnehlataSharma05/.virtualenvs/venv/lib/python3.8/site-packages/MySQLdb/cursors.py", line 206, in execute
    res = self._query(query)
  File "/home/SnehlataSharma05/.virtualenvs/venv/lib/python3.8/site-packages/MySQLdb/cursors.py", line 319, in _query
    db.query(q)
  File "/home/SnehlataSharma05/.virtualenvs/venv/lib/python3.8/site-packages/MySQLdb/connections.py", line 259, in query
    _mysql.connection.query(self, query)
django.db.utils.ProgrammingError: (1146, "Table 'SnehlataSharma05$theblog.ablog_category' doesn't exist")

[edit by admin: formatting]

You mentioned earlier that you'd run the migrate management command; did that generate errors? And do you have a migration to create the table in question?

yes sir migrate command generates these errors.

Do you have a migration to create the table in question?