'Setup postgresql for django in windows
I'm learning django and here I'm trying to change the database from the default sqlite3 to postgresql. I've searched all over the internet(google,bing,duckduckgo,..) but no results.
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': 'websitedb',
'USER': 'postgres',
'PASSWORD': 'teamarrow',
'HOST': 'localhost',
'PORT': '5432',
}
}`
Changed the database in settings.py, Installed postgresql,installed psycopg2 for windows from here, Created a new database in pgADMINIII.
In command prompt python manage.py runserver. This is the error:
` Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "C:\Users\Admin\Pictures\website\lib\site-packages\django\core\management\__ini
t__.py", line 385, in execute_from_command_line
utility.execute()
File "C:\Users\Admin\Pictures\website\lib\site-packages\django\core\management\__ini
t__.py", line 354, in execute
django.setup()
File "C:\Users\Admin\Pictures\website\lib\site-packages\django\__init__.py", line 21
, in setup
apps.populate(settings.INSTALLED_APPS)
File "C:\Users\Admin\Pictures\website\lib\site-packages\django\apps\registry.py", li
ne 108, in populate
app_config.import_models(all_models)
File "C:\Users\Admin\Pictures\website\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\Admin\Pictures\website\lib\site-packages\django\contrib\auth\models.p
y", line 40, in <module>
class Permission(models.Model):
File "C:\Users\Admin\Pictures\website\lib\site-packages\django\db\models\base.py", l
ine 122, in __new__
new_class.add_to_class('_meta', Options(meta, **kwargs))
File "C:\Users\Admin\Pictures\website\lib\site-packages\django\db\models\base.py", l
ine 297, in add_to_class
value.contribute_to_class(cls, name)
File "C:\Users\Admin\Pictures\website\lib\site-packages\django\db\models\options.py"
, line 166, in contribute_to_class
self.db_table = truncate_name(self.db_table, connection.ops.max_name_length())
File "C:\Users\Admin\Pictures\website\lib\site-packages\django\db\__init__.py", line
40, in __getattr__
return getattr(connections[DEFAULT_DB_ALIAS], item)
File "C:\Users\Admin\Pictures\website\lib\site-packages\django\db\utils.py", line 24
2, in __getitem__
backend = load_backend(db['ENGINE'])
File "C:\Users\Admin\Pictures\website\lib\site-packages\django\db\utils.py", line 10
8, in load_backend
return import_module('%s.base' % backend_name)
File "C:\Python27\Lib\importlib\__init__.py", line 37, in import_module
__import__(name)
File "C:\Users\Admin\Pictures\website\lib\site-packages\django\db\backends\postgresq
l_psycopg2\base.py", line 27, in <module>
raise ImproperlyConfigured("Error loading psycopg2 module: %s" % e)
django.core.exceptions.ImproperlyConfigured: Error loading psycopg2 module: No module n
amed psycopg2
Please debug where the error is.
Solution 1:[1]
You don't have the PostgreSQL adapter (psycopg2) installed:
Error loading psycopg2 module: No module named psycopg2
You should download the correct version and install it first:
http://www.lfd.uci.edu/~gohlke/pythonlibs/#psycopg
Update: Because of the incorrect formatting of the question I couldn't see that you already downloaded it. Did you take the comments in the "Virtual Environment Installation Notes" into account? You should not double click the installer exe when you are using a virtualenv. Instead, you should use setuptools or distribute to install the package into your virtualenv. See http://www.stickpeople.com/projects/python/win-psycopg/ for details.
Solution 2:[2]
JUST install
pip install pyscopg2
under your folder
Solution 3:[3]
The problem is that pycog2 is not installed.
To install pycog2 type this in your command prompt:
pip install psycopg2
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | |
| Solution 2 | Sabri Baazaoui |
| Solution 3 | glglgl |
