Gozargah / Marzban

Unified GUI Censorship Resistant Solution Powered by Xray
https://t.me/gozargah_marzban
GNU Affero General Public License v3.0
3.73k stars 517 forks source link

Database issue #715

Closed Hiradpi closed 10 months ago

Hiradpi commented 10 months ago

OperationalError: (sqlite3.OperationalError) no such table: admins [SQL: INSERT INTO admins (username, hashed_password, created_at, is_sudo, password_reset_at) VALUES (?, ?, ?, ?, ?)] [parameters: ('Hirad', 'token', '2023-12-26 16:34:19.999443', 1, None)] (Background on this error at: http://sqlalche.me/e/13/e3q8)

so uh.... i think there is no table in database so how do i generate the sqlite database ?

Hiradpi commented 10 months ago

Traceback (most recent call last): File "/usr/bin/alembic", line 33, in sys.exit(load_entry_point('alembic==1.4.3.dev0', 'console_scripts', 'alembic')()) File "/usr/local/lib/python3.9/dist-packages/alembic/config.py", line 641, in main CommandLine(prog=prog).main(argv=argv) File "/usr/local/lib/python3.9/dist-packages/alembic/config.py", line 631, in main self.run_cmd(cfg, options) File "/usr/local/lib/python3.9/dist-packages/alembic/config.py", line 608, in run_cmd fn( File "/usr/local/lib/python3.9/dist-packages/alembic/command.py", line 403, in upgrade script.run_env() File "/usr/local/lib/python3.9/dist-packages/alembic/script/base.py", line 583, in run_env util.load_python_file(self.dir, "env.py") File "/usr/local/lib/python3.9/dist-packages/alembic/util/pyfiles.py", line 95, in load_python_file module = load_module_py(module_id, path) File "/usr/local/lib/python3.9/dist-packages/alembic/util/pyfiles.py", line 113, in load_module_py spec.loader.exec_module(module) # type: ignore File "", line 790, in exec_module File "", line 228, in _call_with_frames_removed File "app/db/migrations/env.py", line 82, in run_migrations_online() File "app/db/migrations/env.py", line 76, in run_migrations_online context.run_migrations() File "", line 8, in run_migrations File "/usr/local/lib/python3.9/dist-packages/alembic/runtime/environment.py", line 948, in run_migrations self.get_context().run_migrations(kw) File "/usr/local/lib/python3.9/dist-packages/alembic/runtime/migration.py", line 627, in run_migrations step.migration_fn(kw) File "/root/Marzban/app/db/migrations/versions/8e849e06f131_proxy_table.py", line 47, in upgrade batch_op.drop_column('settings') File "/usr/lib/python3.9/contextlib.py", line 124, in exit next(self.gen) File "/usr/local/lib/python3.9/dist-packages/alembic/operations/base.py", line 398, in batch_alter_table impl.flush() File "/usr/local/lib/python3.9/dist-packages/alembic/operations/batch.py", line 164, in flush batch_impl._create(self.impl) File "/usr/local/lib/python3.9/dist-packages/alembic/operations/batch.py", line 448, in _create op_impl.create_table(self.new_table) File "/usr/local/lib/python3.9/dist-packages/alembic/ddl/impl.py", line 366, in create_table self._exec(schema.CreateTable(table)) File "/usr/local/lib/python3.9/dist-packages/alembic/ddl/impl.py", line 207, in _exec return conn.execute(construct, multiparams) File "/usr/lib/python3/dist-packages/sqlalchemy/engine/base.py", line 1011, in execute return meth(self, multiparams, params) File "/usr/lib/python3/dist-packages/sqlalchemy/sql/ddl.py", line 72, in _execute_on_connection return connection._execute_ddl(self, multiparams, params) File "/usr/lib/python3/dist-packages/sqlalchemy/engine/base.py", line 1068, in _execute_ddl ret = self._execute_context( File "/usr/lib/python3/dist-packages/sqlalchemy/engine/base.py", line 1316, in _execute_context self._handle_dbapi_exception( File "/usr/lib/python3/dist-packages/sqlalchemy/engine/base.py", line 1510, in _handle_dbapiexception util.raise( File "/usr/lib/python3/dist-packages/sqlalchemy/util/compat.py", line 182, in raise_ raise exception File "/usr/lib/python3/dist-packages/sqlalchemy/engine/base.py", line 1276, in _execute_context self.dialect.do_execute( File "/usr/lib/python3/dist-packages/sqlalchemy/engine/default.py", line 609, in do_execute cursor.execute(statement, parameters) sqlalchemy.exc.OperationalError: (sqlite3.OperationalError) no such column: proxy_type [SQL: CREATE TABLE _alembic_tmp_users ( id INTEGER NOT NULL, username VARCHAR(34), status VARCHAR(7), used_traffic BIGINT, data_limit BIGINT, expire INTEGER, created_at DATETIME DEFAULT (CURRENT_TIMESTAMP), PRIMARY KEY (id), CONSTRAINT userstatus CHECK (status IN ('active', 'limited', 'expired')), CONSTRAINT proxytypes CHECK (proxy_type IN ('VMess', 'VLESS', 'Trojan', 'Shadowsocks')) )

] (Background on this error at: http://sqlalche.me/e/13/e3q8)

Hiradpi commented 10 months ago

INFO: 5.112.142.26:18974 - "GET /api/system HTTP/1.1" 500 Internal Server Error ERROR: Exception in ASGI application Traceback (most recent call last): File "/usr/lib/python3/dist-packages/sqlalchemy/engine/base.py", line 1276, in _execute_context self.dialect.do_execute( File "/usr/lib/python3/dist-packages/sqlalchemy/engine/default.py", line 609, in do_execute cursor.execute(statement, parameters) sqlite3.OperationalError: no such table: admins

The above exception was the direct cause of the following exception:

Traceback (most recent call last): File "/usr/local/lib/python3.9/dist-packages/uvicorn/protocols/http/h11_impl.py", line 408, in run_asgi result = await app( # type: ignore[func-returns-value] File "/usr/local/lib/python3.9/dist-packages/uvicorn/middleware/proxy_headers.py", line 84, in call return await self.app(scope, receive, send) File "/usr/local/lib/python3.9/dist-packages/fastapi/applications.py", line 1054, in call await super().call(scope, receive, send) File "/usr/local/lib/python3.9/dist-packages/starlette/applications.py", line 122, in call await self.middleware_stack(scope, receive, send) File "/usr/local/lib/python3.9/dist-packages/starlette/middleware/errors.py", line 184, in call raise exc File "/usr/local/lib/python3.9/dist-packages/starlette/middleware/errors.py", line 162, in call await self.app(scope, receive, _send) File "/usr/local/lib/python3.9/dist-packages/starlette/middleware/cors.py", line 83, in call await self.app(scope, receive, send) File "/usr/local/lib/python3.9/dist-packages/starlette/middleware/exceptions.py", line 79, in call raise exc File "/usr/local/lib/python3.9/dist-packages/starlette/middleware/exceptions.py", line 68, in call await self.app(scope, receive, sender) File "/usr/local/lib/python3.9/dist-packages/starlette/routing.py", line 718, in call await route.handle(scope, receive, send) File "/usr/local/lib/python3.9/dist-packages/starlette/routing.py", line 276, in handle await self.app(scope, receive, send) File "/usr/local/lib/python3.9/dist-packages/starlette/routing.py", line 66, in app response = await func(request) File "/usr/local/lib/python3.9/dist-packages/fastapi/routing.py", line 299, in app raise e File "/usr/local/lib/python3.9/dist-packages/fastapi/routing.py", line 294, in app raw_response = await run_endpoint_function( File "/usr/local/lib/python3.9/dist-packages/fastapi/routing.py", line 193, in run_endpoint_function return await run_in_threadpool(dependant.call, *values) File "/usr/local/lib/python3.9/dist-packages/starlette/concurrency.py", line 41, in run_in_threadpool return await anyio.to_thread.run_sync(func, args) File "/usr/local/lib/python3.9/dist-packages/anyio/to_thread.py", line 33, in run_sync return await get_asynclib().run_sync_in_worker_thread( File "/usr/local/lib/python3.9/dist-packages/anyio/_backends/_asyncio.py", line 877, in run_sync_in_worker_thread return await future File "/usr/local/lib/python3.9/dist-packages/anyio/_backends/_asyncio.py", line 807, in run result = context.run(func, *args) File "/root/Marzban/app/views/system.py", line 20, in get_system_stats dbadmin: Union[Admin, None] = crud.get_admin(db, admin.username) File "/root/Marzban/app/db/crud.py", line 395, in get_admin return db.query(Admin).filter(Admin.username == username).first() File "/usr/lib/python3/dist-packages/sqlalchemy/orm/query.py", line 3429, in first ret = list(self[0:1]) File "/usr/lib/python3/dist-packages/sqlalchemy/orm/query.py", line 3203, in getitem return list(res) File "/usr/lib/python3/dist-packages/sqlalchemy/orm/query.py", line 3535, in iter return self._execute_and_instances(context) File "/usr/lib/python3/dist-packages/sqlalchemy/orm/query.py", line 3560, in _execute_and_instances result = conn.execute(querycontext.statement, self._params) File "/usr/lib/python3/dist-packages/sqlalchemy/engine/base.py", line 1011, in execute return meth(self, multiparams, params) File "/usr/lib/python3/dist-packages/sqlalchemy/sql/elements.py", line 298, in _execute_on_connection return connection._execute_clauseelement(self, multiparams, params) File "/usr/lib/python3/dist-packages/sqlalchemy/engine/base.py", line 1124, in _execute_clauseelement ret = self._execute_context( File "/usr/lib/python3/dist-packages/sqlalchemy/engine/base.py", line 1316, in _execute_context self._handle_dbapi_exception( File "/usr/lib/python3/dist-packages/sqlalchemy/engine/base.py", line 1510, in _handle_dbapiexception util.raise( File "/usr/lib/python3/dist-packages/sqlalchemy/util/compat.py", line 182, in raise_ raise exception File "/usr/lib/python3/dist-packages/sqlalchemy/engine/base.py", line 1276, in _execute_context self.dialect.do_execute( File "/usr/lib/python3/dist-packages/sqlalchemy/engine/default.py", line 609, in do_execute cursor.execute(statement, parameters) sqlalchemy.exc.OperationalError: (sqlite3.OperationalError) no such table: admins [SQL: SELECT admins.id AS admins_id, admins.username AS admins_username, admins.hashed_password AS admins_hashed_password, admins.created_at AS admins_created_at, admins.is_sudo AS admins_is_sudo, admins.password_reset_at AS admins_password_reset_at FROM admins WHERE admins.username = ? LIMIT ? OFFSET ?] [parameters: ('Hirad', 1, 0)] (Background on this error at: http://sqlalche.me/e/13/e3q8) ^CINFO: Shutting down INFO: Waiting for application shutdown. INFO: Application shutdown complete. INFO: Finished server process [7112]

M03ED commented 10 months ago

you running marzban manual ?

Hiradpi commented 10 months ago

yes i downgraded the version to my other servers version that i installed a month ago it's all fixed but it had something to do with database tables and merging it with the env but overall it shouldn't be this hard to install it i mean why don't you automate it so people not have to deal with the docker and it's dumb mirrors(which are allways broken or banned) .not everyone use ubuntu i mean im not lazy or something my main server's os is arch linux but the documentation is very unclear the requirements.txt had some issues too i had to install some of the dependencies manually because of version conflict

thank you :)

M03ED commented 10 months ago

Docker it's for automation You probably update your marzban but didn't upgrade your database You need to use 'alembic upgrade head' to upgrade database If you use docker on servers and you get 403 response you can change your docker file and download images from github Like this : services: marzban: image: ghcr.io/gozargah/marzban:latest restart: always env_file: .env network_mode: host volumes:

Hiradpi commented 10 months ago

i did not update anything it was a new server i got these errors from

Hiradpi commented 10 months ago

Traceback (most recent call last): File "/usr/bin/alembic", line 33, in sys.exit(load_entry_point('alembic==1.4.3.dev0', 'console_scripts', 'alembic')()) File "/usr/local/lib/python3.9/dist-packages/alembic/config.py", line 641, in main CommandLine(prog=prog).main(argv=argv) File "/usr/local/lib/python3.9/dist-packages/alembic/config.py", line 631, in main self.run_cmd(cfg, options) File "/usr/local/lib/python3.9/dist-packages/alembic/config.py", line 608, in run_cmd fn( File "/usr/local/lib/python3.9/dist-packages/alembic/command.py", line 403, in upgrade script.run_env() File "/usr/local/lib/python3.9/dist-packages/alembic/script/base.py", line 583, in run_env util.load_python_file(self.dir, "env.py") File "/usr/local/lib/python3.9/dist-packages/alembic/util/pyfiles.py", line 95, in load_python_file module = load_module_py(module_id, path) File "/usr/local/lib/python3.9/dist-packages/alembic/util/pyfiles.py", line 113, in load_module_py spec.loader.exec_module(module) # type: ignore File "", line 790, in exec_module File "", line 228, in _call_with_frames_removed File "app/db/migrations/env.py", line 82, in run_migrations_online() File "app/db/migrations/env.py", line 76, in run_migrations_online context.run_migrations() File "", line 8, in run_migrations File "/usr/local/lib/python3.9/dist-packages/alembic/runtime/environment.py", line 948, in run_migrations self.get_context().run_migrations(kw) File "/usr/local/lib/python3.9/dist-packages/alembic/runtime/migration.py", line 627, in run_migrations step.migration_fn(kw) File "/root/Marzban/app/db/migrations/versions/8e849e06f131_proxy_table.py", line 47, in upgrade batch_op.drop_column('settings') File "/usr/lib/python3.9/contextlib.py", line 124, in exit next(self.gen) File "/usr/local/lib/python3.9/dist-packages/alembic/operations/base.py", line 398, in batch_alter_table impl.flush() File "/usr/local/lib/python3.9/dist-packages/alembic/operations/batch.py", line 164, in flush batch_impl._create(self.impl) File "/usr/local/lib/python3.9/dist-packages/alembic/operations/batch.py", line 448, in _create op_impl.create_table(self.new_table) File "/usr/local/lib/python3.9/dist-packages/alembic/ddl/impl.py", line 366, in create_table self._exec(schema.CreateTable(table)) File "/usr/local/lib/python3.9/dist-packages/alembic/ddl/impl.py", line 207, in _exec return conn.execute(construct, multiparams) File "/usr/lib/python3/dist-packages/sqlalchemy/engine/base.py", line 1011, in execute return meth(self, multiparams, params) File "/usr/lib/python3/dist-packages/sqlalchemy/sql/ddl.py", line 72, in _execute_on_connection return connection._execute_ddl(self, multiparams, params) File "/usr/lib/python3/dist-packages/sqlalchemy/engine/base.py", line 1068, in _execute_ddl ret = self._execute_context( File "/usr/lib/python3/dist-packages/sqlalchemy/engine/base.py", line 1316, in _execute_context self._handle_dbapi_exception( File "/usr/lib/python3/dist-packages/sqlalchemy/engine/base.py", line 1510, in _handle_dbapiexception util.raise( File "/usr/lib/python3/dist-packages/sqlalchemy/util/compat.py", line 182, in raise_ raise exception File "/usr/lib/python3/dist-packages/sqlalchemy/engine/base.py", line 1276, in _execute_context self.dialect.do_execute( File "/usr/lib/python3/dist-packages/sqlalchemy/engine/default.py", line 609, in do_execute cursor.execute(statement, parameters) sqlalchemy.exc.OperationalError: (sqlite3.OperationalError) no such column: proxy_type [SQL: CREATE TABLE _alembic_tmp_users ( id INTEGER NOT NULL, username VARCHAR(34), status VARCHAR(7), used_traffic BIGINT, data_limit BIGINT, expire INTEGER, created_at DATETIME DEFAULT (CURRENT_TIMESTAMP), PRIMARY KEY (id), CONSTRAINT userstatus CHECK (status IN ('active', 'limited', 'expired')), CONSTRAINT proxytypes CHECK (proxy_type IN ('VMess', 'VLESS', 'Trojan', 'Shadowsocks')) )

] (Background on this error at: http://sqlalche.me/e/13/e3q8)

sorry i forgot to mention this was the output of alembic upgrade head

M03ED commented 10 months ago

You didn't generate database file Read documentations again https://gozargah.github.io/marzban/docs/installation

M03ED commented 10 months ago

Which migration ?

Hiradpi commented 10 months ago

dmn i missed this document i did not see it well as they always say "do it less , do it always" thank you

M03ED commented 10 months ago

Have a good day ;)