Hi kolodzie, thanks for your reply!! I run your snippet … and receive that:
...:
---------------------------------------------------------------------------
IntegrityError Traceback (most recent call last)
<ipython-input-4-5435e503fa23> in <module>()
2 if sat != SystemAppType.none and OAuthApplication.query.filter_by(system_app_type=sat).first() is None:
3 db.session.add(OAuthApplication(system_app_type=sat, **sat.default_data))
----> 4 db.session.commit()
5
/usr/lib64/python2.7/site-packages/sqlalchemy/orm/scoping.pyc in do(self, *args, **kwargs)
151 def instrument(name):
152 def do(self, *args, **kwargs):
--> 153 return getattr(self.registry(), name)(*args, **kwargs)
154 return do
155
/usr/lib64/python2.7/site-packages/sqlalchemy/orm/session.pyc in commit(self)
941 raise sa_exc.InvalidRequestError("No transaction is begun.")
942
--> 943 self.transaction.commit()
944
945 def prepare(self):
/usr/lib64/python2.7/site-packages/sqlalchemy/orm/session.pyc in commit(self)
465 self._assert_active(prepared_ok=True)
466 if self._state is not PREPARED:
--> 467 self._prepare_impl()
468
469 if self._parent is None or self.nested:
/usr/lib64/python2.7/site-packages/sqlalchemy/orm/session.pyc in _prepare_impl(self)
445 if self.session._is_clean():
446 break
--> 447 self.session.flush()
448 else:
449 raise exc.FlushError(
/usr/lib64/python2.7/site-packages/sqlalchemy/orm/session.pyc in flush(self, objects)
2252 try:
2253 self._flushing = True
-> 2254 self._flush(objects)
2255 finally:
2256 self._flushing = False
/usr/lib64/python2.7/site-packages/sqlalchemy/orm/session.pyc in _flush(self, objects)
2378 except:
2379 with util.safe_reraise():
-> 2380 transaction.rollback(_capture_exception=True)
2381
2382 def bulk_save_objects(
/usr/lib64/python2.7/site-packages/sqlalchemy/util/langhelpers.pyc in __exit__(self, type_, value, traceback)
64 self._exc_info = None # remove potential circular references
65 if not self.warn_only:
---> 66 compat.reraise(exc_type, exc_value, exc_tb)
67 else:
68 if not compat.py3k and self._exc_info and self._exc_info[1]:
/usr/lib64/python2.7/site-packages/sqlalchemy/orm/session.pyc in _flush(self, objects)
2342 self._warn_on_events = True
2343 try:
-> 2344 flush_context.execute()
2345 finally:
2346 self._warn_on_events = False
/usr/lib64/python2.7/site-packages/sqlalchemy/orm/unitofwork.pyc in execute(self)
389 self.dependencies,
390 postsort_actions):
--> 391 rec.execute(self)
392
393 def finalize_flush_changes(self):
/usr/lib64/python2.7/site-packages/sqlalchemy/orm/unitofwork.pyc in execute(self, uow)
554 uow.states_for_mapper_hierarchy(
555 self.mapper, False, False),
--> 556 uow
557 )
558
/usr/lib64/python2.7/site-packages/sqlalchemy/orm/persistence.pyc in save_obj(base_mapper, states, uowtransaction, single)
179 _emit_insert_statements(base_mapper, uowtransaction,
180 cached_connections,
--> 181 mapper, table, insert)
182
183 _finalize_insert_update_commands(
/usr/lib64/python2.7/site-packages/sqlalchemy/orm/persistence.pyc in _emit_insert_statements(base_mapper, uowtransaction, cached_connections, mapper, table, i nsert, bookkeeping)
864 else:
865 result = cached_connections[connection].\
--> 866 execute(statement, params)
867
868 primary_key = result.context.inserted_primary_key
/usr/lib64/python2.7/site-packages/sqlalchemy/engine/base.pyc in execute(self, object, *multiparams, **params)
946 raise exc.ObjectNotExecutableError(object)
947 else:
--> 948 return meth(self, multiparams, params)
949
950 def _execute_function(self, func, multiparams, params):
/usr/lib64/python2.7/site-packages/sqlalchemy/sql/elements.pyc in _execute_on_connection(self, connection, multiparams, params)
267 def _execute_on_connection(self, connection, multiparams, params):
268 if self.supports_execution:
--> 269 return connection._execute_clauseelement(self, multiparams, params)
270 else:
271 raise exc.ObjectNotExecutableError(self)
/usr/lib64/python2.7/site-packages/sqlalchemy/engine/base.pyc in _execute_clauseelement(self, elem, multiparams, params)
1058 compiled_sql,
1059 distilled_params,
-> 1060 compiled_sql, distilled_params
1061 )
1062 if self._has_events or self.engine._has_events:
/usr/lib64/python2.7/site-packages/sqlalchemy/engine/base.pyc in _execute_context(self, dialect, constructor, statement, parameters, *args)
1198 parameters,
1199 cursor,
-> 1200 context)
1201
1202 if self._has_events or self.engine._has_events:
/usr/lib64/python2.7/site-packages/sqlalchemy/engine/base.pyc in _handle_dbapi_exception(self, e, statement, parameters, cursor, context)
1411 util.raise_from_cause(
1412 sqlalchemy_exception,
-> 1413 exc_info
1414 )
1415 else:
/usr/lib64/python2.7/site-packages/sqlalchemy/util/compat.pyc in raise_from_cause(exception, exc_info)
201 exc_type, exc_value, exc_tb = exc_info
202 cause = exc_value if exc_value is not exception else None
--> 203 reraise(type(exception), exception, tb=exc_tb, cause=cause)
204
205 if py3k:
/usr/lib64/python2.7/site-packages/sqlalchemy/engine/base.pyc in _execute_context(self, dialect, constructor, statement, parameters, *args)
1191 statement,
1192 parameters,
-> 1193 context)
1194 except BaseException as e:
1195 self._handle_dbapi_exception(
/usr/lib64/python2.7/site-packages/sqlalchemy/engine/default.pyc in do_execute(self, cursor, statement, parameters, context)
505
506 def do_execute(self, cursor, statement, parameters, context=None):
--> 507 cursor.execute(statement, parameters)
508
509 def do_execute_no_params(self, cursor, statement, context=None):
IntegrityError: (psycopg2.IntegrityError) duplicate key value violates unique constraint "ix_uq_applications_name_lower"
DETAIL: Key (lower(name::text))=(checkin app) already exists.
[SQL: 'INSERT INTO oauth.applications (name, description, client_id, client_secret, default_scopes, redirect_uris, is_enabled, is_trusted, system_app_type) V ALUES (%(name)s, %(description)s, %(client_id)s, %(client_secret)s, %(default_scopes)s, %(redirect_uris)s, %(is_enabled)s, %(is_trusted)s, %(system_app_type)s ) RETURNING oauth.applications.id'] [parameters: {'is_enabled': True, 'redirect_uris': [u'http://localhost'], 'name': u'Checkin App', 'is_trusted': True, 'cli ent_id': UUID('48b6be7e-8199-487c-b535-08f70e8e38f9'), 'client_secret': UUID('2ca87230-3187-48f3-a420-c4ab968eb93a'), 'system_app_type': <SystemAppType.checki n: 1>, 'default_scopes': [u'registrants'], 'description': u'The checkin app for mobile devices allows scanning ticket QR codes and checking-in event participa nts.'}] (Background on this error at: http://sqlalche.me/e/gkpj)