I am developing Authentication service using FastAPI.
While developing, there is a critical error and I can't develop anymore.
I want to create some tables after creating auth_service database but it
I am developing Authentication service using FastAPI. While developing, there is a critical error and I can’t develop anymore. I want to create some tables after creating auth_service database but it couldn’t do well.. Of course, auth_service database is available. And I am sure that there is no error in models.
This is my env.py file for alembic.
import asyncio from logging.config import fileConfig from sqlalchemy import engine_from_config, pool from sqlalchemy.engine import Connection from sqlalchemy.ext.asyncio import AsyncEngine from alembic import context from src.db.url import get_sqlalchemy_url from src.db.base_class import Base from src.models import * # necessarily to import something from file where your models are stored # this is the Alembic Config object, which provides # access to the values within the .ini file in use. config = context.config # Interpret the config file for Python logging. # This line sets up loggers basically. if config.config_file_name is not None: fileConfig(config.config_file_name) target_metadata = Base.metadata target_metadata.naming_convention = { “ix”: “ix_%(column_0_label)s”, “uq”: “uq_%(table_name)s_%(column_0_name)s”, “ck”: “ck_%(table_name)s_%(constraint_name)s”, “fk”: “fk_%(table_name)s_%(column_0_name)” “s_%(referred_table_name)s”, “pk”: “pk_%(table_name)s” } # other values from the config, defined by the needs of env.py, # can be acquired: # my_important_option = config.get_main_option(“my_important_option”) # … etc. def run_migrations_offline() -> None: “””Run migrations in ‘offline’ mode. This configures the context with just a URL and not an Engine, though an Engine is acceptable here as well. By skipping the Engine creation we don’t even need a DBAPI to be available. Calls to context.execute() here emit the given string to the script output. “”” url = get_sqlalchemy_url() context.configure( url=url, target_metadata=target_metadata, literal_binds=True, dialect_opts={“paramstyle”: “named”}, ) with context.begin_transaction(): context.run_migrations() def do_run_migrations(connection: Connection) -> None: context.configure(connection=connection, target_metadata=target_metadata) with context.begin_transaction(): context.run_migrations() async def run_migrations_online() -> None: “””Run migrations in ‘online’ mode. In this scenario we need to create an Engine and associate a connection with the context. “”” configuration = config.get_section(config.config_ini_section) configuration[“sqlalchemy.url”] = get_sqlalchemy_url() connectable = AsyncEngine( engine_from_config( configuration, prefix=”sqlalchemy.”, poolclass=pool.NullPool, future=True, ) ) async with connectable.connect() as connection: await connection.run_sync(do_run_migrations) await connectable.dispose() if context.is_offline_mode(): run_migrations_offline() else: asyncio.run(run_migrations_online())
I run with this command : alembic revision –autogenerate -m “new migration” But there is an error like this.
Traceback (most recent call last): File “C:UsersDarknessAppDataLocalProgramsPythonPython39librunpy.py”, line 197, in _run_module_as_main return _run_code(code, main_globals, None, File “C:UsersDarknessAppDataLocalProgramsPythonPython39librunpy.py”, line 87, in _run_code exec(code, run_globals) File “C:UsersDarkness.virtualenvspythonProjectScriptsalembic.exe__main__.py”, line 7, in File “C:UsersDarkness.virtualenvspythonProjectlibsite-packagesalembicconfig.py”, line 590, in main CommandLine(prog=prog).main(argv=argv) File “C:UsersDarkness.virtualenvspythonProjectlibsite-packagesalembicconfig.py”, line 584, in main self.run_cmd(cfg, options) File “C:UsersDarkness.virtualenvspythonProjectlibsite-packagesalembicconfig.py”, line 561, in run_cmd fn( File “C:UsersDarkness.virtualenvspythonProjectlibsite-packagesalembiccommand.py”, line 229, in revision script_directory.run_env() File “C:UsersDarkness.virtualenvspythonProjectlibsite-packagesalembicscriptbase.py”, line 569, in run_env util.load_python_file(self.dir, “env.py”) File “C:UsersDarkness.virtualenvspythonProjectlibsite-packagesalembicutilpyfiles.py”, line 94, in load_python_file module = load_module_py(module_id, path) File “C:UsersDarkness.virtualenvspythonProjectlibsite-packagesalembicutilpyfiles.py”, line 110, in load_module_py spec.loader.exec_module(module) # type: ignore File ““, line 850, in exec_module File ““, line 228, in _call_with_frames_removed File “alembicenv.py”, line 100, in asyncio.run(run_migrations_online()) File “C:UsersDarknessAppDataLocalProgramsPythonPython39libasynciorunners.py”, line 44, in run return loop.run_until_complete(main) File “C:UsersDarknessAppDataLocalProgramsPythonPython39libasynciobase_events.py”, line 647, in run_until_complete return future.result() File “alembicenv.py”, line 91, in run_migrations_online async with connectable.connect() as connection: File “C:UsersDarkness.virtualenvspythonProjectlibsite-packagessqlalchemyextasynciobase.py”, line 60, in __aenter__ return await self.start(is_ctxmanager=True) File “C:UsersDarkness.virtualenvspythonProjectlibsite-packagessqlalchemyextasyncioengine.py”, line 157, in start await (greenlet_spawn(self.sync_engine.connect)) File “C:UsersDarkness.virtualenvspythonProjectlibsite-packagessqlalchemyutil_concurrency_py3k.py”, line 126, in greenlet_spawn result = context.throw(*sys.exc_info()) File “C:UsersDarkness.virtualenvspythonProjectlibsite-packagessqlalchemyfutureengine.py”, line 406, in connect return super(Engine, self).connect() File “C:UsersDarkness.virtualenvspythonProjectlibsite-packagessqlalchemyenginebase.py”, line 3315, in connect return self._connection_cls(self, close_with_result=close_with_result) File “C:UsersDarkness.virtualenvspythonProjectlibsite-packagessqlalchemyenginebase.py”, line 96, in __init__ else engine.raw_connection() File “C:UsersDarkness.virtualenvspythonProjectlibsite-packagessqlalchemyenginebase.py”, line 3394, in raw_connection return self._wrap_pool_connect(self.pool.connect, _connection) File “C:UsersDarkness.virtualenvspythonProjectlibsite-packagessqlalchemyenginebase.py”, line 3361, in _wrap_pool_connect return fn() File “C:UsersDarkness.virtualenvspythonProjectlibsite-packagessqlalchemypoolbase.py”, line 320, in connect return _ConnectionFairy._checkout(self) File “C:UsersDarkness.virtualenvspythonProjectlibsite-packagessqlalchemypoolbase.py”, line 884, in _checkout fairy = _ConnectionRecord.checkout(pool) File “C:UsersDarkness.virtualenvspythonProjectlibsite-packagessqlalchemypoolbase.py”, line 486, in checkout rec = pool._do_get() File “C:UsersDarkness.virtualenvspythonProjectlibsite-packagessqlalchemypoolimpl.py”, line 256, in _do_get return self._create_connection() File “C:UsersDarkness.virtualenvspythonProjectlibsite-packagessqlalchemypoolbase.py”, line 266, in _create_connection return _ConnectionRecord(self) File “C:UsersDarkness.virtualenvspythonProjectlibsite-packagessqlalchemypoolbase.py”, line 381, in __init__ self.__connect() File “C:UsersDarkness.virtualenvspythonProjectlibsite-packagessqlalchemypoolbase.py”, line 678, in __connect pool.logger.debug(“Error on connect(): %s”, e) File “C:UsersDarkness.virtualenvspythonProjectlibsite-packagessqlalchemyutillanghelpers.py”, line 70, in __exit__ compat.raise_( File “C:UsersDarkness.virtualenvspythonProjectlibsite-packagessqlalchemyutilcompat.py”, line 208, in raise_ raise exception File “C:UsersDarkness.virtualenvspythonProjectlibsite-packagessqlalchemypoolbase.py”, line 673, in __connect self.dbapi_connection = connection = pool._invoke_creator(self) File “C:UsersDarkness.virtualenvspythonProjectlibsite-packagessqlalchemyenginecreate.py”, line 578, in connect return dialect.connect(*cargs, **cparams) File “C:UsersDarkness.virtualenvspythonProjectlibsite-packagessqlalchemyenginedefault.py”, line 598, in connect return self.dbapi.connect(*cargs, **cparams) File “C:UsersDarkness.virtualenvspythonProjectlibsite-packagessqlalchemydialectspostgresqlasyncpg.py”, line 780, in connect await_only(self.asyncpg.connect(*arg, **kw)), File “C:UsersDarkness.virtualenvspythonProjectlibsite-packagessqlalchemyutil_concurrency_py3k.py”, line 68, in await_only return current.driver.switch(awaitable) File “C:UsersDarkness.virtualenvspythonProjectlibsite-packagessqlalchemyutil_concurrency_py3k.py”, line 121, in greenlet_spawn value = await result File “C:UsersDarkness.virtualenvspythonProjectlibsite-packagesasyncpgconnection.py”, line 2092, in connect return await connect_utils._connect( File “C:UsersDarkness.virtualenvspythonProjectlibsite-packagesasyncpgconnect_utils.py”, line 881, in _connect return await _connect_addr( File “C:UsersDarkness.virtualenvspythonProjectlibsite-packagesasyncpgconnect_utils.py”, line 773, in _connect_addr return await __connect_addr(params, timeout, True, *args) File “C:UsersDarkness.virtualenvspythonProjectlibsite-packagesasyncpgconnect_utils.py”, line 831, in __connect_addr await compat.wait_for(connected, timeout=timeout) File “C:UsersDarkness.virtualenvspythonProjectlibsite-packagesasyncpgcompat.py”, line 56, in wait_for return await asyncio.wait_for(fut, timeout) File “C:UsersDarknessAppDataLocalProgramsPythonPython39libasynciotasks.py”, line 479, in wait_for return fut.result() asyncpg.exceptions.InvalidCatalogNameError: database “auth_service” does not exist
I am developing Authentication service using FastAPI.
While developing, there is a critical error and I can't develop anymore.
I want to create some tables after creating auth_service database but it