ustream / openduty

An open source Alerting and incident escalation tool
MIT License
787 stars 188 forks source link

Can't finish syncdb #68

Open dbazhal opened 7 years ago

dbazhal commented 7 years ago

Did nothing, just created mysql db, user, started using "getting started" instructions and it fails:

(oduty)[bajal@bajal:~/git/openduty]# python manage.py syncdb
/home/bajal/oduty/lib/python2.7/site-packages/schedule/models/calendars.py:8: RemovedInDjango19Warning: django.contrib.contenttypes.generic is deprecated and will be removed in Django 1.9. Its contents have been moved to the fields, forms, and admin submodules of django.contrib.contenttypes.
  from django.contrib.contenttypes import generic

/home/bajal/oduty/lib/python2.7/site-packages/django/core/management/commands/syncdb.py:24: RemovedInDjango19Warning: The syncdb command will be removed in Django 1.9
  warnings.warn("The syncdb command will be removed in Django 1.9", RemovedInDjango19Warning)

Operations to perform:
  Synchronize unmigrated apps: openduty, staticfiles, djcelery, messages, templatetags, django_tables2, notification, rest_framework, bootstrap3, django_tables2_simplefilter
  Apply all migrations: schedule, admin, django_twilio, sessions, kombu_transport_django, contenttypes, auth
Synchronizing apps without migrations:
  Creating tables...
    Creating table openduty_token
    Creating table openduty_schedulepolicy
    Creating table openduty_service
    Creating table openduty_eventlog
    Creating table openduty_incident
    Creating table openduty_servicetokens
    Creating table openduty_schedulepolicyrule
    Creating table openduty_userprofile
    Creating table openduty_servicesilenced
    Creating table openduty_incidentsilenced
    Creating table celery_taskmeta
    Creating table celery_tasksetmeta
    Creating table djcelery_intervalschedule
    Creating table djcelery_crontabschedule
    Creating table djcelery_periodictasks
    Creating table djcelery_periodictask
    Creating table djcelery_workerstate
    Creating table djcelery_taskstate
    Creating table openduty_usernotificationmethod
    Creating table openduty_schedulednotification
    Running deferred SQL...
Traceback (most recent call last):
  File "manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "/home/bajal/oduty/lib/python2.7/site-packages/django/core/management/__init__.py", line 354, in execute_from_command_line
    utility.execute()
  File "/home/bajal/oduty/lib/python2.7/site-packages/django/core/management/__init__.py", line 346, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/home/bajal/oduty/lib/python2.7/site-packages/django/core/management/base.py", line 394, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/home/bajal/oduty/lib/python2.7/site-packages/django/core/management/base.py", line 445, in execute
    output = self.handle(*args, **options)
  File "/home/bajal/oduty/lib/python2.7/site-packages/django/core/management/commands/syncdb.py", line 25, in handle
    call_command("migrate", **options)
  File "/home/bajal/oduty/lib/python2.7/site-packages/django/core/management/__init__.py", line 120, in call_command
    return command.execute(*args, **defaults)
  File "/home/bajal/oduty/lib/python2.7/site-packages/django/core/management/base.py", line 445, in execute
    output = self.handle(*args, **options)
  File "/home/bajal/oduty/lib/python2.7/site-packages/django/core/management/commands/migrate.py", line 179, in handle
    created_models = self.sync_apps(connection, executor.loader.unmigrated_apps)
  File "/home/bajal/oduty/lib/python2.7/site-packages/django/core/management/commands/migrate.py", line 318, in sync_apps
    cursor.execute(statement)
  File "/home/bajal/oduty/lib/python2.7/site-packages/django/db/backends/utils.py", line 79, in execute
    return super(CursorDebugWrapper, self).execute(sql, params)
  File "/home/bajal/oduty/lib/python2.7/site-packages/django/db/backends/utils.py", line 64, in execute
    return self.cursor.execute(sql, params)
  File "/home/bajal/oduty/lib/python2.7/site-packages/django/db/utils.py", line 98, in __exit__
    six.reraise(dj_exc_type, dj_exc_value, traceback)
  File "/home/bajal/oduty/lib/python2.7/site-packages/django/db/backends/utils.py", line 62, in execute
    return self.cursor.execute(sql)
  File "/home/bajal/oduty/lib/python2.7/site-packages/django/db/backends/mysql/base.py", line 124, in execute
    return self.cursor.execute(query, args)
  File "/home/bajal/oduty/lib/python2.7/site-packages/MySQLdb/cursors.py", line 205, in execute
    self.errorhandler(self, exc, value)
  File "/home/bajal/oduty/lib/python2.7/site-packages/MySQLdb/connections.py", line 36, in defaulterrorhandler
    raise errorclass, errorvalue
django.db.utils.OperationalError: (1005, 'Can\'t create table `openduty`.`#sql-331e_14` (errno: 150 "Foreign key constraint is incorrectly formed")')
deathowl commented 7 years ago

let me check

krutaw commented 7 years ago

Are you using MySQL or MariaDB?

dbazhal commented 7 years ago

It's mariadb

krutaw commented 7 years ago

That's where the problem lies. I had similar problems when using MariaDB and ended up chucking it and going back to MySQL via the community repos. I simply forgot to file a ticket about it while having the problem, but I can confirm it's related to the interactiong with MariaDB.

michaelluich commented 7 years ago

I found it was a permissions issue. I had created the openduty user before the database. all I had to do was grant the user permissions on the DB. I chose to just give them full permissions as this is my initial test.

GRANT ALL ON openduty.* TO 'openduty'@'%';

sofixa commented 7 years ago

You can also do the following:

python manage.py migrate auth
python manage.py migrate
python manage.py syncdb
deathowl commented 7 years ago

since @sofixa helped with this one i'm closing this one.

sh1r0 commented 7 years ago

Hi @deathowl, I tried to create database from scratch in docker (openduty and database are in different containers), but I got the same error as @dbazhal had. I've tried mysql 5.5/5.6 and mariadb 10.1, and got errors about foreign key on all the three. in addition, I've tried steps provided by @sofixa as well. My script is shown below. NOTE: openduty docker is from https://github.com/openduty/openduty

if ! mysql -h $DATABASES_DEFAULT_HOST -u $DATABASES_DEFAULT_USER -p$DATABASES_DEFAULT_PASSWORD -e 'SHOW DATABASES;' | grep -q $DATABASES_DEFAULT_NAME; then
    mysql -h $DATABASES_DEFAULT_HOST -u $DATABASES_DEFAULT_USER -p$DATABASES_DEFAULT_PASSWORD -e "CREATE DATABASE $DATABASES_DEFAULT_NAME;"

    export DJANGO_SETTINGS_MODULE=openduty.settings_docker
    python manage.py syncdb
    python manage.py migrate
    python manage.py collectstatic --noinput
fi
pataquets commented 7 years ago

Same here. Manually tried with all solutions in the thread, both with MySQL and MariaDB and always getting foreign key errors. In both cases I've manually granted ALL privileges to OD MySQL user, just slightly different error texts: With MySQL 5.6.x:

/usr/local/lib/python2.7/site-packages/schedule/models/calendars.py:8: RemovedInDjango19Warning: django.contrib.contenttypes.generic is deprecated and will be removed in Django 1.9. Its contents have been moved to the fields, forms, and admin submodules of django.contrib.contenttypes.
  from django.contrib.contenttypes import generic

Operations to perform:
  Synchronize unmigrated apps: openduty, staticfiles, djcelery, messages, templatetags, django_tables2, notification, rest_framework, bootstrap3, django_tables2_simplefilter
  Apply all migrations: schedule, admin, django_twilio, sessions, kombu_transport_django, contenttypes, auth
Synchronizing apps without migrations:
  Creating tables...
    Creating table openduty_token
    Creating table openduty_schedulepolicy
    Creating table openduty_service
    Creating table openduty_eventlog
    Creating table openduty_incident
    Creating table openduty_servicetokens
    Creating table openduty_schedulepolicyrule
    Creating table openduty_userprofile
    Creating table openduty_servicesilenced
    Creating table openduty_incidentsilenced
    Creating table celery_taskmeta
    Creating table celery_tasksetmeta
    Creating table djcelery_intervalschedule
    Creating table djcelery_crontabschedule
    Creating table djcelery_periodictasks
    Creating table djcelery_periodictask
    Creating table djcelery_workerstate
    Creating table djcelery_taskstate
    Creating table openduty_usernotificationmethod
    Creating table openduty_schedulednotification
    Running deferred SQL...
Traceback (most recent call last):
  File "manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "/usr/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 354, in execute_from_command_line
    utility.execute()
  File "/usr/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 346, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/usr/local/lib/python2.7/site-packages/django/core/management/base.py", line 394, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/usr/local/lib/python2.7/site-packages/django/core/management/base.py", line 445, in execute
    output = self.handle(*args, **options)
  File "/usr/local/lib/python2.7/site-packages/django/core/management/commands/migrate.py", line 179, in handle
    created_models = self.sync_apps(connection, executor.loader.unmigrated_apps)
  File "/usr/local/lib/python2.7/site-packages/django/core/management/commands/migrate.py", line 318, in sync_apps
    cursor.execute(statement)
  File "/usr/local/lib/python2.7/site-packages/django/db/backends/utils.py", line 79, in execute
    return super(CursorDebugWrapper, self).execute(sql, params)
  File "/usr/local/lib/python2.7/site-packages/django/db/backends/utils.py", line 64, in execute
    return self.cursor.execute(sql, params)
  File "/usr/local/lib/python2.7/site-packages/django/db/utils.py", line 98, in __exit__
    six.reraise(dj_exc_type, dj_exc_value, traceback)
  File "/usr/local/lib/python2.7/site-packages/django/db/backends/utils.py", line 62, in execute
    return self.cursor.execute(sql)
  File "/usr/local/lib/python2.7/site-packages/django/db/backends/mysql/base.py", line 124, in execute
    return self.cursor.execute(query, args)
  File "/usr/local/lib/python2.7/site-packages/MySQLdb/cursors.py", line 205, in execute
    self.errorhandler(self, exc, value)
  File "/usr/local/lib/python2.7/site-packages/MySQLdb/connections.py", line 36, in defaulterrorhandler
    raise errorclass, errorvalue
django.db.utils.IntegrityError: (1215, 'Cannot add foreign key constraint')

With MariaDB 10.x:

/usr/local/lib/python2.7/site-packages/schedule/models/calendars.py:8: RemovedInDjango19Warning: django.contrib.contenttypes.generic is deprecated and will be removed in Django 1.9. Its contents have been moved to the fields, forms, and admin submodules of django.contrib.contenttypes.
  from django.contrib.contenttypes import generic

Operations to perform:
  Synchronize unmigrated apps: openduty, staticfiles, djcelery, messages, templatetags, django_tables2, notification, rest_framework, bootstrap3, django_tables2_simplefilter
  Apply all migrations: schedule, admin, django_twilio, sessions, kombu_transport_django, contenttypes, auth
Synchronizing apps without migrations:
  Creating tables...
    Creating table openduty_token
    Creating table openduty_schedulepolicy
    Creating table openduty_service
    Creating table openduty_eventlog
    Creating table openduty_incident
    Creating table openduty_servicetokens
    Creating table openduty_schedulepolicyrule
    Creating table openduty_userprofile
    Creating table openduty_servicesilenced
    Creating table openduty_incidentsilenced
    Creating table celery_taskmeta
    Creating table celery_tasksetmeta
    Creating table djcelery_intervalschedule
    Creating table djcelery_crontabschedule
    Creating table djcelery_periodictasks
    Creating table djcelery_periodictask
    Creating table djcelery_workerstate
    Creating table djcelery_taskstate
    Creating table openduty_usernotificationmethod
    Creating table openduty_schedulednotification
    Running deferred SQL...
Traceback (most recent call last):
  File "manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "/usr/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 354, in execute_from_command_line
    utility.execute()
  File "/usr/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 346, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/usr/local/lib/python2.7/site-packages/django/core/management/base.py", line 394, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/usr/local/lib/python2.7/site-packages/django/core/management/base.py", line 445, in execute
    output = self.handle(*args, **options)
  File "/usr/local/lib/python2.7/site-packages/django/core/management/commands/migrate.py", line 179, in handle
    created_models = self.sync_apps(connection, executor.loader.unmigrated_apps)
  File "/usr/local/lib/python2.7/site-packages/django/core/management/commands/migrate.py", line 318, in sync_apps
    cursor.execute(statement)
  File "/usr/local/lib/python2.7/site-packages/django/db/backends/utils.py", line 79, in execute
    return super(CursorDebugWrapper, self).execute(sql, params)
  File "/usr/local/lib/python2.7/site-packages/django/db/backends/utils.py", line 64, in execute
    return self.cursor.execute(sql, params)
  File "/usr/local/lib/python2.7/site-packages/django/db/utils.py", line 98, in __exit__
    six.reraise(dj_exc_type, dj_exc_value, traceback)
  File "/usr/local/lib/python2.7/site-packages/django/db/backends/utils.py", line 62, in execute
    return self.cursor.execute(sql)
  File "/usr/local/lib/python2.7/site-packages/django/db/backends/mysql/base.py", line 124, in execute
    return self.cursor.execute(query, args)
  File "/usr/local/lib/python2.7/site-packages/MySQLdb/cursors.py", line 205, in execute
    self.errorhandler(self, exc, value)
  File "/usr/local/lib/python2.7/site-packages/MySQLdb/connections.py", line 36, in defaulterrorhandler
    raise errorclass, errorvalue
django.db.utils.OperationalError: (1005, 'Can\'t create table `openduty`.`#sql-1_6` (errno: 150 "Foreign key constraint is incorrectly formed")')
alvarezbruned commented 7 years ago

It's the same with me. I can not install it

pataquets commented 7 years ago

@deathowl : Any tips? Anything else needed from us to help diagnose where is the problem? TIA.

kjetilmjos commented 7 years ago

I got the same error, but changed the order to this instead: python manage.py migrate auth python manage.py migrate python manage.py syncdb python manage.py collectstatic python manage.py runserver

got through without errors

gaubapravar commented 6 years ago

guys, please help me out. Stuck on this:

self.build_graph()

File "/home/openduty/openduty/env/lib/python2.7/site-packages/django/db/migrations/loader.py", line 191, in build_graph self.applied_migrations = recorder.applied_migrations() File "/home/openduty/openduty/env/lib/python2.7/site-packages/django/db/migrations/recorder.py", line 59, in applied_migrations self.ensure_schema() File "/home/openduty/openduty/env/lib/python2.7/site-packages/django/db/migrations/recorder.py", line 49, in ensure_schema if self.Migration._meta.db_table in self.connection.introspection.table_names(self.connection.cursor()): File "/home/openduty/openduty/env/lib/python2.7/site-packages/django/db/backends/base/base.py", line 164, in cursor cursor = self.make_cursor(self._cursor()) File "/home/openduty/openduty/env/lib/python2.7/site-packages/django/db/backends/dummy/base.py", line 21, in complain raise ImproperlyConfigured("settings.DATABASES is improperly configured. " django.core.exceptions.ImproperlyConfigured: settings.DATABASES is improperly configured. Please supply the ENGINE value. Check settings documentation for more details.

Unfortunately, I did not get through . Here is the database portion of settings.py. I am using Mysql 5.7(which is sort of running perfect.).

if 'test' in sys.argv: DATABASES = { 'default': { 'ENGINE': 'django.db.backends.mysql', 'NAME': 'test', 'USER': 'openduty', 'PASSWORD': 'Openduty@123', 'HOST': 'localhost', 'PORT': '3306', } }

Any idea where I am going wrong @deathowl @pataquets @dbazhal

truekonrads commented 5 years ago

The installation docs should be updated