8

I had django-oscar's sample app sandbox deployed on my website at example.com . i wanted to move that to example.com:8000 and run another project at example.com url. I successfully did the second part, and when you enter example.com, you can see the newer django project up and running, but the thing is, the first django project which was django-oscar's sandbox, wont respond properly.

when you enter example.com:8000, you see the current debug log:

no such column: django_content_type.name
Request Method: GET
Request URL:    http://example.com:8000/fa/
Django Version: 1.7.8
Exception Type: OperationalError
Exception Value:    
no such column: django_content_type.name
Exception Location: /usr/local/lib/python2.7/dist-packages/django/db/backends/sqlite3/base.py in execute, line 485
Python Executable:  /usr/bin/python
Python Version: 2.7.3
Python Path:    
['/var/www/setak/setakenv/setakmain/django-oscar/sites/sandbox',
 '/usr/lib/python2.7',
 '/usr/lib/python2.7/plat-linux2',
 '/usr/lib/python2.7/lib-tk',
 '/usr/lib/python2.7/lib-old',
 '/usr/lib/python2.7/lib-dynload',
 '/usr/local/lib/python2.7/dist-packages',
 '/usr/lib/python2.7/dist-packages',
 '/usr/lib/python2.7/dist-packages/PIL',
 '/usr/lib/python2.7/dist-packages/gst-0.10',
 '/usr/lib/python2.7/dist-packages/gtk-2.0',
 '/usr/lib/python2.7/dist-packages/ubuntu-sso-client',
 '/usr/lib/python2.7/dist-packages/ubuntuone-client',
 '/usr/lib/python2.7/dist-packages/ubuntuone-control-panel',
 '/usr/lib/python2.7/dist-packages/ubuntuone-couch',
 '/usr/lib/python2.7/dist-packages/ubuntuone-installer',
 '/usr/lib/python2.7/dist-packages/ubuntuone-storage-protocol']

now i googled this error and I didn't get any valuable results.

Also, when I run

sudo python manage.py migrate

the following happens, which also I did not find any correct resolution to fix:

Operations to perform:
  Synchronize unmigrated apps: reports_dashboard, treebeard, oscar, communications_dashboard, reviews_dashboard, debug_toolbar, widget_tweaks, offers_dashboard, catalogue_dashboard, sitemaps, compressor, django_extensions, dashboard, thumbnail, haystack, ranges_dashboard, checkout, gateway, django_tables2
  Apply all migrations: customer, promotions, shipping, wishlists, offer, admin, sessions, contenttypes, auth, payment, reviews, analytics, catalogue, flatpages, sites, address, basket, partner, order, voucher
Synchronizing apps without migrations:
  Creating tables...
  Installing custom SQL...
  Installing indexes...
Running migrations:
  No migrations to apply.
Traceback (most recent call last):
  File "manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 385, in execute_from_command_line
    utility.execute()
  File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 377, 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 288, in run_from_argv
    self.execute(*args, **options.__dict__)
  File "/usr/local/lib/python2.7/dist-packages/django/core/management/base.py", line 338, in execute
    output = self.handle(*args, **options)
  File "/usr/local/lib/python2.7/dist-packages/django/core/management/commands/migrate.py", line 165, in handle
    emit_post_migrate_signal(created_models, self.verbosity, self.interactive, connection.alias)
  File "/usr/local/lib/python2.7/dist-packages/django/core/management/sql.py", line 268, in emit_post_migrate_signal
    using=db)
  File "/usr/local/lib/python2.7/dist-packages/django/dispatch/dispatcher.py", line 198, in send
    response = receiver(signal=self, sender=sender, **named)
  File "/usr/local/lib/python2.7/dist-packages/django/contrib/auth/management/__init__.py", line 83, in create_permissions
    ctype = ContentType.objects.db_manager(using).get_for_model(klass)
  File "/usr/local/lib/python2.7/dist-packages/django/contrib/contenttypes/models.py", line 58, in get_for_model
    " is migrated before trying to migrate apps individually."
RuntimeError: Error creating new content types. Please make sure contenttypes is migrated before trying to migrate apps individually.

update 1: I am also using django 1.7.8 for this.

update 2: I changed my version of Django to 1.8.1, the makemigrations and migrate commands worked. Then I ran the server again, and now I get this error in my log: ( I also deleted the apache settings since they were irrelevant!)

Traceback (most recent call last):
  File "/usr/lib/python2.7/wsgiref/handlers.py", line 85, in run
    self.result = application(self.environ, self.start_response)
  File "/usr/local/lib/python2.7/dist-packages/django/contrib/staticfiles/handlers.py", line 63, in __call__
    return self.application(environ, start_response)
  File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/wsgi.py", line 170, in __call__
    self.load_middleware()
  File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/base.py", line 50, in load_middleware
    mw_class = import_string(middleware_path)
  File "/usr/local/lib/python2.7/dist-packages/django/utils/module_loading.py", line 26, in import_string
    module = import_module(module_path)
  File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module
    __import__(name)
ImportError: No module named transaction
Ashkan Kazemi
  • 1,077
  • 8
  • 26
  • Did you try what django is suggesting and migrate contenttypes first? – ger.s.brett May 18 '15 at 14:35
  • @ger.s.brett yes i did. the same error happens! – Ashkan Kazemi May 18 '15 at 14:43
  • Did you start off with django 1.8, and later downgrade to django 1.7.8 ? – karthikr May 18 '15 at 14:46
  • @karthikr well, i think I did. the story was that one time i upgraded to 1.8 from 1.7.x and then when i saw it is not working, i downgraded to 1.7.8 – Ashkan Kazemi May 18 '15 at 14:49
  • Easiest tthing would be to recreate the database .that is,if you don't have much data – karthikr May 18 '15 at 14:58
  • @karthikr that is not an option, but thanks! – Ashkan Kazemi May 18 '15 at 15:00
  • Here is an alternative: Can you try and "unapply" a migration? (Example: python manage.py migrate contenttypes 0001) ? NOte that this wont work on SQLite – karthikr May 18 '15 at 15:22
  • the database is actually SQLite, i quess, but when i run this command, the following is written in the log: Target specific migration: 0001_initial, from contenttypes and then the same error happens again. – Ashkan Kazemi May 18 '15 at 15:24
  • This exception is raised for errors which are related to MySQL's operations. For example: too many connections; a host name could not be resolved; bad handshake; server is shutting down, communication errors. – bob marti Mar 02 '17 at 09:22

2 Answers2

17

I could finally solve my problem. The problem was that I used django 1.8 to run manage.py migrate and the project was developed under django 1.7.1, so the migrations broke things up.

So what I did was that I installed django 1.8.1 again, ran manage.py migrate contenttypes 0001, then uninstalled django 1.8.1, installed django 1.7.8 and ran manage.py runserver and everything went back to normal and worked fine.

thumbtackthief
  • 6,093
  • 10
  • 41
  • 87
Ashkan Kazemi
  • 1,077
  • 8
  • 26
  • 1
    This answer helped me get to a solution even though I couldn't follow it exactly because I couldn't run any manage.py command without seeing this error (an app everything else depended on tried to access contenttypes in its initialization, even if no database was defined). Instead I created a separate settings file "initial.py" that only had django apps defined in INSTALLED_APPS. I was able to run migrate using this settings module first, and then switch to my regular settings module to complete all of my project specific migrations. – Brett Dec 27 '15 at 17:55
  • This exception is raised for errors which are related to MySQL's operations. For example: too many connections; a host name could not be resolved; bad handshake; server is shutting down, communication errors. – bob marti Mar 02 '17 at 09:22
0

I had the same issue. In my case I used Django 1.10 to create my local database but I need to use old Django version (1.7) to do some tests, so I deleted my local database and run manage.py migrate with Django 1.7 then the error has gone.

Alternatively, instead of deleting local database, the database can be kept and moved back to the project once it needed when the project run with Django 1.10

wei
  • 4,267
  • 2
  • 23
  • 18