简体   繁体   中英

Django says that table doesn't exist while it does

My ultimate goal is to deploy Django application on new server and all I have is raw image of disk of the old server. I have everything set up on the new server: uwsgi, python, mysql, django etc. But let's get to my problem: when I run

uwsgi --http :8001 --module propotolki.wsgi

It runs without errors but when I try to access it through browser I get the following stack trace in the logs:

Internal Server Error: / 
Traceback (most recent call last):
  File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/base.py", line 90, in get_response
    response = middleware_method(request)
  File "./apps/middleware/middleware.py", line 11, in process_request
    if RedirectHandler.objects.filter(is_active=True, redirect_from=request.path).exists():
  File "/usr/local/lib/python2.7/dist-packages/django/db/models/query.py", line 512, in exists
    return self.query.has_results(using=self.db)
  File "/usr/local/lib/python2.7/dist-packages/django/db/models/sql/query.py", line 409, in has_results
    return bool(compiler.execute_sql(SINGLE))
  File "/usr/local/lib/python2.7/dist-packages/django/db/models/sql/compiler.py", line 781, in execute_sql
    cursor.execute(sql, params)
  File "/usr/local/lib/python2.7/dist-packages/django/db/backends/util.py", line 53, in execute
    return self.cursor.execute(sql, params)
  File "/usr/local/lib/python2.7/dist-packages/django/db/utils.py", line 99, in __exit__
    six.reraise(dj_exc_type, dj_exc_value, traceback)
  File "/usr/local/lib/python2.7/dist-packages/django/db/backends/util.py", line 53, in execute
    return self.cursor.execute(sql, params)
  File "/usr/local/lib/python2.7/dist-packages/django/db/backends/mysql/base.py", line 124, in execute
    return self.cursor.execute(query, args)
  File "/usr/local/lib/python2.7/dist-packages/MySQLdb/cursors.py", line 205, in execute
    self.errorhandler(self, exc, value)
  File "/usr/local/lib/python2.7/dist-packages/MySQLdb/connections.py", line 36, in defaulterrorhandler
    raise errorclass, errorvalue
ProgrammingError: (1146, "Table 'propotolki.middleware_redirecthandler' doesn't exist")

Here's what I get from mysql console, proving that the table does exist:

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| propotolki         |
+--------------------+
4 rows in set (0.00 sec)

mysql> use propotolki;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> show tables;
+---------------------------------------+
| Tables_in_propotolki                  |
+---------------------------------------+
| auth_group                            |
| auth_group_permissions                |
| auth_permission                       |
| auth_user                             |
| auth_user_groups                      |
| auth_user_user_permissions            |
| bla_files_blafile                     |
| bla_files_sitefiles                   |
| calc_anglealum                        |
| calc_anglesteelwhite                  |
| calc_baseheight                       |
| calc_cellsize                         |
| calc_color                            |
| calc_outgo_bc_25                      |
| calc_pendant                          |
| calc_price                            |
| calc_roofcolor                        |
| calc_size                             |
| catalog_brand                         |
| catalog_category                      |
| catalog_colortemperature              |
| catalog_diffuser                      |
| catalog_floortype                     |
| catalog_lightoutput                   |
| catalog_order                         |
| catalog_orderinfo                     |
| catalog_product                       |
| catalog_product_categories            |
| catalog_product_color_temperature     |
| catalog_product_diffuser              |
| catalog_product_floor_type            |
| catalog_product_light_output          |
| catalog_product_related               |
| catalog_product_related_categories    |
| catalog_productsliderimage            |
| catalog_sessionbasket                 |
| chunks_chunk                          |
| chunks_group                          |
| chunks_image                          |
| chunks_media                          |
| django_admin_log                      |
| django_content_type                   |
| django_ipgeobase_ipgeobase            |
| django_ipgeobase_ipgeobase_city       |
| django_ipgeobase_ipgeobase_country    |
| django_ipgeobase_ipgeobase_region     |
| django_session                        |
| django_site                           |
| feedback_feedback                     |
| gallery_gallerygroup                  |
| gallery_galleryimage                  |
| left_menu_leftmenuitem                |
| middleware_breadcrumbs                |
| middleware_flatpages                  |
| middleware_redirecthandler            |
| middleware_slidebar                   |
| propotolki.django_content_type        |
| propotolki.middleware_redirecthandler |
| south_migrationhistory                |
| thumbnail_kvstore                     |
| watson_searchentry                    |
+---------------------------------------+
61 rows in set (0.01 sec)

I am far from being Django expert, so please ask for any needed info. I also tried doing python manager.py syncdb but I get similar error telling that other tables also doesn't exist:

# python manage.py syncdb
Syncing...
Creating tables ...
Traceback (most recent call last):
  File "manage.py", line 9, in <module>
    execute_from_command_line(sys.argv)
  File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 399, in execute_from_command_line
    utility.execute()
  File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 392, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/usr/local/lib/python2.7/dist-packages/django/core/management/base.py", line 242, in run_from_argv
    self.execute(*args, **options.__dict__)
  File "/usr/local/lib/python2.7/dist-packages/django/core/management/base.py", line 285, in execute
    output = self.handle(*args, **options)
  File "/usr/local/lib/python2.7/dist-packages/django/core/management/base.py", line 415, in handle
    return self.handle_noargs(**options)
  File "/usr/local/lib/python2.7/dist-packages/south/management/commands/syncdb.py", line 92, in handle_noargs
    syncdb.Command().execute(**options)
  File "/usr/local/lib/python2.7/dist-packages/django/core/management/base.py", line 285, in execute
    output = self.handle(*args, **options)
  File "/usr/local/lib/python2.7/dist-packages/django/core/management/base.py", line 415, in handle
    return self.handle_noargs(**options)
  File "/usr/local/lib/python2.7/dist-packages/django/core/management/commands/syncdb.py", line 112, in handle_noargs
    emit_post_sync_signal(created_models, verbosity, interactive, db)
  File "/usr/local/lib/python2.7/dist-packages/django/core/management/sql.py", line 216, in emit_post_sync_signal
    interactive=interactive, db=db)
  File "/usr/local/lib/python2.7/dist-packages/django/dispatch/dispatcher.py", line 185, in send
    response = receiver(signal=self, sender=sender, **named)
  File "/usr/local/lib/python2.7/dist-packages/django/contrib/auth/management/__init__.py", line 82, in create_permissions
    ctype = ContentType.objects.db_manager(db).get_for_model(klass)
  File "/usr/local/lib/python2.7/dist-packages/django/contrib/contenttypes/models.py", line 47, in get_for_model
    defaults = {'name': smart_text(opts.verbose_name_raw)},
  File "/usr/local/lib/python2.7/dist-packages/django/db/models/manager.py", line 154, in get_or_create
    return self.get_queryset().get_or_create(**kwargs)
  File "/usr/local/lib/python2.7/dist-packages/django/db/models/query.py", line 373, in get_or_create
    return self.get(**lookup), False
  File "/usr/local/lib/python2.7/dist-packages/django/db/models/query.py", line 301, in get
    num = len(clone)
  File "/usr/local/lib/python2.7/dist-packages/django/db/models/query.py", line 77, in __len__
    self._fetch_all()
  File "/usr/local/lib/python2.7/dist-packages/django/db/models/query.py", line 854, in _fetch_all
    self._result_cache = list(self.iterator())
  File "/usr/local/lib/python2.7/dist-packages/django/db/models/query.py", line 220, in iterator
    for row in compiler.results_iter():
  File "/usr/local/lib/python2.7/dist-packages/django/db/models/sql/compiler.py", line 710, in results_iter
    for rows in self.execute_sql(MULTI):
  File "/usr/local/lib/python2.7/dist-packages/django/db/models/sql/compiler.py", line 781, in execute_sql
    cursor.execute(sql, params)
  File "/usr/local/lib/python2.7/dist-packages/django/db/backends/util.py", line 53, in execute
    return self.cursor.execute(sql, params)
  File "/usr/local/lib/python2.7/dist-packages/django/db/utils.py", line 99, in __exit__
    six.reraise(dj_exc_type, dj_exc_value, traceback)
  File "/usr/local/lib/python2.7/dist-packages/django/db/backends/util.py", line 53, in execute
    return self.cursor.execute(sql, params)
  File "/usr/local/lib/python2.7/dist-packages/django/db/backends/mysql/base.py", line 124, in execute
    return self.cursor.execute(query, args)
  File "/usr/local/lib/python2.7/dist-packages/MySQLdb/cursors.py", line 205, in execute
    self.errorhandler(self, exc, value)
  File "/usr/local/lib/python2.7/dist-packages/MySQLdb/connections.py", line 36, in defaulterrorhandler
    raise errorclass, errorvalue
django.db.utils.ProgrammingError: (1146, "Table 'propotolki.django_content_type' doesn't exist")

How did your table names end up with a '.' in them? It's a special character.

| propotolki.django_content_type        |
| propotolki.middleware_redirecthandler |

Try:

ALTER TABLE `propotolki.middleware_redirecthandler` RENAME TO middleware_redirecthandler

You will need to do the same for the django_content_type table too.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM