#1 by Yuki
Hello oTree group,
I have the following problem. I created an ultimatum game project (the project name is "proj_ultimatum" and the app name is "Ultimatum") with the "no self" format and tried to test it by typing "otree devserver," but my terminal returned the following error: sqlalchemy.exc.InvalidRequestError: Table 'Ultimatum_subsession' is already defined for this MetaData instance. Specify 'extend_existing=True' to redefine options and columns on an existing Table object.
I did the following but had no success:
- delete db.sqlite3
- delete __pycache__
- make otreezip file and move the oTree project to a different folder
Do you have any idea why this is happening? Other oTree commands, such as otree startapp xxx, return essentially the same error within this project. However, I do not have this problem with other projects - they work perfectly fine.
Any insights into this problem are greatly appreciated. Thanks a lot!
Best,
Yuki
Ps1. I found this related question in the forum, but it didn't include the solution: https://groups.google.com/g/otree/c/Q5q-slC5H94/m/SB_1_OZzBQAJ.
Ps2. Full error message:
Yukis-MacBook-Air:proj_ultimatum yuki$ otree devserver
/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/sqlalchemy/ext/declarative/clsregistry.py:125: SAWarning: This declarative base already contains a class with the same class name and module name as Ultimatum.Subsession, and will be replaced in the string-lookup table.
util.warn(
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/otree/database.py", line 275, in init_orm
models = get_models_module(app)
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/otree/common.py", line 75, in get_models_module
return import_module(module_name)
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 883, in exec_module
File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
File "/Users/yuki/Documents/proj_ultimatum/Ultimatum/__init__.py", line 43, in <module>
class Subsession(BaseSubsession):
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/sqlalchemy/ext/declarative/api.py", line 76, in __init__
_as_declarative(cls, classname, cls.__dict__)
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/sqlalchemy/ext/declarative/base.py", line 131, in _as_declarative
_MapperConfig.setup_mapping(cls, classname, dict_)
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/sqlalchemy/ext/declarative/base.py", line 160, in setup_mapping
cfg_cls(cls_, classname, dict_)
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/sqlalchemy/ext/declarative/base.py", line 190, in __init__
self._setup_table()
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/sqlalchemy/ext/declarative/base.py", line 534, in _setup_table
cls.__table__ = table = table_cls(
File "<string>", line 2, in __new__
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/sqlalchemy/util/deprecations.py", line 139, in warned
return fn(*args, **kwargs)
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/sqlalchemy/sql/schema.py", line 537, in __new__
raise exc.InvalidRequestError(
sqlalchemy.exc.InvalidRequestError: Table 'Ultimatum_subsession' is already defined for this MetaData instance. Specify 'extend_existing=True' to redefine options and columns on an existing Table object.
#2 by Yuki
This issue has been resolved. I made a very simple mistake where I defined Subsession twice in the same __init.py__. Best, Yuki