3

when I makemigrations

i get the following error:

django.db.utils.OperationalError: no such table: django_site

    Traceback (most recent call last):
  File "manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "C:\Python27\lib\site-packages\django\core\management\__init__.py", line 364, in execute_from_command_line
    utility.execute()
  File "C:\Python27\lib\site-packages\django\core\management\__init__.py", line 338, in execute
    django.setup()
  File "C:\Python27\lib\site-packages\django\__init__.py", line 27, in setup
    apps.populate(settings.INSTALLED_APPS)
  File "C:\Python27\lib\site-packages\django\apps\registry.py", line 108, in populate
    app_config.import_models()
  File "C:\Python27\lib\site-packages\django\apps\config.py", line 202, in import_models
    self.models_module = import_module(models_module_name)
  File "C:\Python27\lib\importlib\__init__.py", line 37, in import_module
    __import__(name)
  File "C:\Users\KwanfahArunrerk\Desktop\Sinwattana_repo\trunk\sinwattana3_0\campaign\models.py", line 5, in <module>
    from sinUser.models import sinUser, sinUserCategories
  File "C:\Users\KwanfahArunrerk\Desktop\Sinwattana_repo\trunk\sinwattana3_0\sinUser\models.py", line 4, in <module>
    from functionUtility.sendEmails import sendEmailFunctionIsError
  File "C:\Users\KwanfahArunrerk\Desktop\Sinwattana_repo\trunk\sinwattana3_0\functionUtility\sendEmails.py", line 12, in <module>
    HOSTNAME = Site.objects.get_current().domain
  File "C:\Python27\lib\site-packages\django\contrib\sites\models.py", line 63, in get_current
    return self._get_site_by_id(site_id)
  File "C:\Python27\lib\site-packages\django\contrib\sites\models.py", line 35, in _get_site_by_id
    site = self.get(pk=site_id)
  File "C:\Python27\lib\site-packages\django\db\models\manager.py", line 85, in manager_method
    return getattr(self.get_queryset(), name)(*args, **kwargs)
  File "C:\Python27\lib\site-packages\django\db\models\query.py", line 374, in get
    num = len(clone)
  File "C:\Python27\lib\site-packages\django\db\models\query.py", line 232, in __len__
    self._fetch_all()
  File "C:\Python27\lib\site-packages\django\db\models\query.py", line 1118, in _fetch_all
    self._result_cache = list(self._iterable_class(self))
  File "C:\Python27\lib\site-packages\django\db\models\query.py", line 53, in __iter__
    results = compiler.execute_sql(chunked_fetch=self.chunked_fetch)
  File "C:\Python27\lib\site-packages\django\db\models\sql\compiler.py", line 894, in execute_sql
    raise original_exception
django.db.utils.OperationalError: no such table: django_site

I am newbies python programming

some one can help me

thank you

1
  • Are you creating a fresh project ? Can you give the INSTALLED_APPS ? Commented Oct 10, 2017 at 10:43

5 Answers 5

8

Your sendEmails module has a query at the top level: Site.objects.get_current(). This is run when the module is imported, before migrations have had a chance to run.

You must not do any database actions at this level; put it into a method.

Sign up to request clarification or add additional context in comments.

1 Comment

Ah, after a lot of searching, this answer pointed out the root cause!
3

Add django.contrib.sites in your INSTALLED_APPS and the run migrate command

python manage.py makemigrations
python manage.py migrate

Hope this helps you

1 Comment

can you explain why this fixes the problem?
3

In this case some migrations are still pending so run python manage.py migrate and python manage.py makemigrations app_name

Comments

1

Change "django.contrib.admin" in INSTALLED_APPS to "django.contrib.admin.apps.SimpleAdminConfig" and then run makemigrations command. after that you can revert your changes.

Comments

0
python manage.py migrate
python manage.py makemigrations

Worked for me, had pending migrations.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.