0

I've seen How to use ArrayField in Django using PostgreSQL DB? but the current error I get happens when I call python manage.py migrate I get the error

`  Applying game.0001_initial...Traceback (most recent call last):
  File "manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "/Library/Python/2.7/site-packages/django/core/management/__init__.py", line 338, in execute_from_command_line
    utility.execute()
  File "/Library/Python/2.7/site-packages/django/core/management/__init__.py", line 330, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/Library/Python/2.7/site-packages/django/core/management/base.py", line 390, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/Library/Python/2.7/site-packages/django/core/management/base.py", line 441, in execute
    output = self.handle(*args, **options)
  File "/Library/Python/2.7/site-packages/django/core/management/commands/migrate.py", line 221, in handle
    executor.migrate(targets, plan, fake=fake, fake_initial=fake_initial)
  File "/Library/Python/2.7/site-packages/django/db/migrations/executor.py", line 110, in migrate
    self.apply_migration(states[migration], migration, fake=fake, fake_initial=fake_initial)
  File "/Library/Python/2.7/site-packages/django/db/migrations/executor.py", line 147, in apply_migration
    state = migration.apply(state, schema_editor)
  File "/Library/Python/2.7/site-packages/django/db/migrations/migration.py", line 115, in apply
    operation.database_forwards(self.app_label, schema_editor, old_state, project_state)
  File "/Library/Python/2.7/site-packages/django/db/migrations/operations/models.py", line 59, in database_forwards
    schema_editor.create_model(model)
  File "/Library/Python/2.7/site-packages/django/db/backends/base/schema.py", line 282, in create_model
    self.execute(sql, params or None)
  File "/Library/Python/2.7/site-packages/django/db/backends/base/schema.py", line 107, in execute
    cursor.execute(sql, params)
  File "/Library/Python/2.7/site-packages/django/db/backends/utils.py", line 79, in execute
    return super(CursorDebugWrapper, self).execute(sql, params)
  File "/Library/Python/2.7/site-packages/django/db/backends/utils.py", line 64, in execute
    return self.cursor.execute(sql, params)
  File "/Library/Python/2.7/site-packages/django/db/utils.py", line 97, in __exit__
    six.reraise(dj_exc_type, dj_exc_value, traceback)
  File "/Library/Python/2.7/site-packages/django/db/backends/utils.py", line 62, in execute
    return self.cursor.execute(sql)
  File "/Library/Python/2.7/site-packages/django/db/backends/sqlite3/base.py", line 316, in execute
    return Database.Cursor.execute(self, query)
django.db.utils.OperationalError: near "[10]": syntax error`

After consulting https://docs.djangoproject.com/en/1.9/ref/contrib/postgres/fields/ I still cannot figure out how to use the PostgresSQL fields that are available in Django 1.8 on OS X. This is my first Django app, so instructions would be greatly appreciated. Thanks!

Database of settings.py looks like

`DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
    }
}`
3
  • But you need to show us how did you use the ArrayField? We couldn't just guess what you've done wrong without any code. Commented Dec 31, 2015 at 17:52
  • Can you show us your settings.py section with your database settings? Without the username/password of course. By the looks of "/Library/Python/2.7/site-packages/django/db/backends/sqlite3/base.py" you are using the wrong database backend driver. Commented Dec 31, 2015 at 17:53
  • I've seen this but I only got this error after I put in an ArrayField. stackoverflow.com/questions/33270297/… I've changed nothing in settings.py except INSTALLED_APPS = ( 'django.contrib.admin', ... ... ... 'django.contrib.postgres', 'game', ) Commented Dec 31, 2015 at 17:57

1 Answer 1

2

The issue is you haven't setup django to use Postgres, currently it is using the default of sqlite3. If you modify your settings.py database section to look something similar to this you should not see that error anymore.

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.postgresql_psycopg2',
        'NAME': 'db_name',                      
        'USER': 'db_user',
        'PASSWORD': 'db_user_password',
        'HOST': 'localhost',
        'PORT': '5432',
    }
}

Or if you would like a postgres backend that automatically reconnects on disconnection you can use a custom postgres backend called postgreconnect. The same instruction works for both, but instead just use django-postgreconnect instead of django.db.backends.postgresql_psycopg2.

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

6 Comments

I believe the default is 5432. If that doesn't work you can look at the postgresql.conf in your $PGDATA directory.
I am getting django.db.utils.OperationalError: could not connect to server: No such file or directory using 5432. :/
Did you fill out the HOST section in the settings? Is your postgres server running? Is it listening on localhost or even 0.0.0.0? You can verify this by running netstat -na | grep 5432
It is listening in on localhost.5432. I can't figure out what to use for Name and User
Ok, did you put localhost as the HOST in your database configuration? Also, you may have to configure postgres if you haven't already. I am not an expert on that so you may have to find a guide to setup postgres correctly. digitalocean.com/community/tutorials/… may help you, the section Create a Database and Database User should point you in the right direction.
|

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.