owocki / pytrader

cryptocurrency trading robot
MIT License
1.93k stars 432 forks source link

Database Setup #3

Closed densmirnov closed 8 years ago

densmirnov commented 8 years ago

Hi! First of all thanks for great contribution! Second when i'm trying to deploy it locally after ./manage.py migrate i've got error that settings.DATABASES is improperly configured. But even after adding database config to setting i've still get an error, this time: django.db.utils.OperationalError: no such column: history_predictiontest.type

owocki commented 8 years ago

Hi @densmirnov thanks for the post. We'll get you up & running right quick. Can you post the full stack trace please?

owocki commented 8 years ago

Here is a sample DB config:

#postgres

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.postgresql_psycopg2',  # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'.
        'NAME': 'trader',                      # Or path to database file if using sqlite3.
        # The following settings are not used with sqlite3:
        'USER': 'trader',
        'PASSWORD': '<pw>',
        'HOST': '127.0.0.1',  # '127.0.0.1',                      # Empty for localhost through domain sockets or '127.0.0.1' for localhost through TCP.
        'PORT': '',  # '5124',                      # Set to empty string for default.
        'ATOMIC_REQUESTS': True,
    },
}
#sqllite

import os
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))

_DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
    }
}
densmirnov commented 8 years ago

Thanks for answer! I've tried both formats and got errors in both cases. For postgresql trace is:

./manage.py syncdb

Operations to perform:
  Synchronize unmigrated apps: staticfiles, chartit, messages
  Apply all migrations: admin, contenttypes, sessions, auth, history
Synchronizing apps without migrations:
  Creating tables...
    Running deferred SQL...
  Installing custom SQL...
Running migrations:
  Rendering model states... DONE
  Applying history.0013_auto_20160222_2046...Traceback (most recent call last):
  File "./manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "/Users/densmirnov/.virtualenvs/pytrader/lib/python2.7/site-packages/django/core/management/__init__.py", line 338, in execute_from_command_line
    utility.execute()
  File "/Users/densmirnov/.virtualenvs/pytrader/lib/python2.7/site-packages/django/core/management/__init__.py", line 330, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/Users/densmirnov/.virtualenvs/pytrader/lib/python2.7/site-packages/django/core/management/base.py", line 390, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/Users/densmirnov/.virtualenvs/pytrader/lib/python2.7/site-packages/django/core/management/base.py", line 441, in execute
    output = self.handle(*args, **options)
  File "/Users/densmirnov/.virtualenvs/pytrader/lib/python2.7/site-packages/django/core/management/commands/syncdb.py", line 25, in handle
    call_command("migrate", **options)
  File "/Users/densmirnov/.virtualenvs/pytrader/lib/python2.7/site-packages/django/core/management/__init__.py", line 120, in call_command
    return command.execute(*args, **defaults)
  File "/Users/densmirnov/.virtualenvs/pytrader/lib/python2.7/site-packages/django/core/management/base.py", line 441, in execute
    output = self.handle(*args, **options)
  File "/Users/densmirnov/.virtualenvs/pytrader/lib/python2.7/site-packages/django/core/management/commands/migrate.py", line 221, in handle
    executor.migrate(targets, plan, fake=fake, fake_initial=fake_initial)
  File "/Users/densmirnov/.virtualenvs/pytrader/lib/python2.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 "/Users/densmirnov/.virtualenvs/pytrader/lib/python2.7/site-packages/django/db/migrations/executor.py", line 147, in apply_migration
    state = migration.apply(state, schema_editor)
  File "/Users/densmirnov/.virtualenvs/pytrader/lib/python2.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 "/Users/densmirnov/.virtualenvs/pytrader/lib/python2.7/site-packages/django/db/migrations/operations/special.py", line 183, in database_forwards
    self.code(from_state.apps, schema_editor)
  File "/Developer/PyTrader/history/migrations/0013_auto_20160222_2046.py", line 13, in backfill_messagetype
    for pt in PredictionTest.objects.all():
  File "/Users/densmirnov/.virtualenvs/pytrader/lib/python2.7/site-packages/django/db/models/query.py", line 162, in __iter__
    self._fetch_all()
  File "/Users/densmirnov/.virtualenvs/pytrader/lib/python2.7/site-packages/django/db/models/query.py", line 965, in _fetch_all
    self._result_cache = list(self.iterator())
  File "/Users/densmirnov/.virtualenvs/pytrader/lib/python2.7/site-packages/django/db/models/query.py", line 238, in iterator
    results = compiler.execute_sql()
  File "/Users/densmirnov/.virtualenvs/pytrader/lib/python2.7/site-packages/django/db/models/sql/compiler.py", line 840, in execute_sql
    cursor.execute(sql, params)
  File "/Users/densmirnov/.virtualenvs/pytrader/lib/python2.7/site-packages/django/db/backends/utils.py", line 79, in execute
    return super(CursorDebugWrapper, self).execute(sql, params)
  File "/Users/densmirnov/.virtualenvs/pytrader/lib/python2.7/site-packages/django/db/backends/utils.py", line 64, in execute
    return self.cursor.execute(sql, params)
  File "/Users/densmirnov/.virtualenvs/pytrader/lib/python2.7/site-packages/django/db/utils.py", line 97, in __exit__
    six.reraise(dj_exc_type, dj_exc_value, traceback)
  File "/Users/densmirnov/.virtualenvs/pytrader/lib/python2.7/site-packages/django/db/backends/utils.py", line 64, in execute
    return self.cursor.execute(sql, params)
django.db.utils.ProgrammingError: column history_predictiontest.type does not exist
LINE 1: ...ated_on", "history_predictiontest"."modified_on", "history_p...
                                                             ^
HINT:  Perhaps you meant to reference the column "history_predictiontest.time".
owocki commented 8 years ago

Hi @densmirnov. @richardpetithory was nice enough to flatten the migrations and submit a PR. mind pulling from master, destroying your DB, and running the migrations again?

densmirnov commented 8 years ago

@owocki Yeah! Now everything is working smootly! Thanks a lot!