안녕하세요, 강사님. 아래와 같이 End-Point에 생성이 안되어서 문의드립니다. 강사님처럼 Legacy serving 창이 뜨지도 않을 뿐더러 [use model for inference]를 클릭해서 생성하려고 해도 아무런 반응이 없더라구요. 제가 설정에서 뭔가를 잘못한 것일까요?? 아니면 현재 구독이 무료 계정이라서 그런걸까요..? 마지막 강의까지 다 와서 막혀버렸네요 ㅠ
employee_id와 manager_id를 사용해서 셀프조인 하는 과정에서 자신의 상사를 모두 표시하고 싶다는 생각이 들었습니다. SELECT a.employee_id, a.name, b.employee_id, b.name, c.employee_id, c.name, d.employee_id, d.name, e.employee_id, e.name FROM employees a left join employees b on a.manager_id = b.employee_id left join employees c on b.manager_id = c.employee_id left join employees d on c.manager_id = d.employee_id left join employees e on d.manager_id = e.employee_id 이와같이 직원 코드가 있고 상사 코드가 있는 경우 자기로부터 가장 높은 상사까지 한 행에 다 출력하고 싶은 경우에는 어떤 방법이 최선인지 알고 싶습니다. 지금은 단순히 데이터 개수가 적기 때문에 몇번의 조인으로 해결되었지만 실무에서 데이터 개수가 많다고 할때 이와같이 구하려면 어떻게 구해야하는지 궁금합니다. 즉 위 코드처럼 여러번 조인을 쓰는게 아니라 원하는 결과를 얻을 때 까지 자동으로 반복시킬 방법이 있는지 궁금합니다.
google colab 오픈 하여 새노트를 열면 로드 에러가 발생합니다. 어떻게 해야 하나요? ============================= A network error occurred and the request could not be completed. GapiError: A network error occurred and the request could not be completed. at $ L.PE [as constructor] ( https://ssl.gstatic.com/colaboratory-static/common/a17fd496db698d4637390557595457ce/external_binary_l10n__ko.js:1733:732 ) at new $L ( https://ssl.gstatic.com/colaboratory-
31강에서 구현된 users.py의 read_all_users는 화면에 구현이 안되는 것이 맞는 것인가요? Users의 POST /users 밑에 GET /users/all로 있어야 할 것 같은데... ===> PC를 재시작 후 다시 서버를 실행해 보니 나타납니다. DB Browser에서 특정 User의 is_admin을 true로 수정하고 저장까지 완료하고 난 후, 각각의 User들로 로그인해보았습니다. 그런데, is_admin이 false인 모든 User들도 read_all_users의 endpoint인 /users/all에서 모든 회원들의 리스트가 조회가 됩니다. /docs 페이지라서 그런 것인지 아니면 잘못 구현된 것인지 궁금합니다. 강의에서는 docs에서의 이런 상황에 대한 언급이 없어 질문을 드립니다.
30강을 완강후에 Postman을 통해 post로 http://127.0.0.1:8000/token 으로 요청을 보냈는데 아래 처럼 응답으로 토큰이 날아오지 않습니다. 422 Unprocessable Content 에러가 나오구요~~ oauth2_scheme = OAuth2PasswordBearer(tokenUrl="token") # http://<your_domain>/token 뭐가 문제일런지요? postman사용법에 맞게 된것 같지가 않은데요..... @@@ 추가 질문 그리고, 더불어서 발급받은 토큰을 /docs에서 Authentication의 어디에 입력을 해서 테스트를 해야 하는지도 같이 안내바랍니다. 여기 client secret에 입력해서 테스트 하는것 같은데.... username, password를 입력해서 로그인하면 token은 잘 생성됩니다. 그리고 이렇게 username과 password로 로그인할 때 생성된 토큰으로 client secret에 입력해서 로그인하면 auth error Error: Unprocessable Content 라는 메시지가 뜹니다. postman사용법이 미숙해서인지 postman에서 post /token으로 날려도 토큰이 반환되어 오질 않습니다. 당연히 docs에서 username, password로 로그인한 후에... 수정, 삭제 권한적용은 잘 적용됩니다.
26강에서 User model를 만들고, Task model의 관계 설정까지 하고 env.py에서 User를 임포트하고 난후 alembic revision --autogenerate를 실행하고, alembic upgrade head 를 실행하면 User 테이블과 Task 모델의 관계설정은 잘 만들어 졌지만, 아래에 보이는 것처럼, 제약조건에 name을 지정하라고 나옴니다. 그래서 name을 지정하고 db를 삭제하고, alembic을 초기화된 상태로 만든 후에 다시 똑같은 과정을 거쳐 실행햇는데, 두번째 alembic revision --autogenerate 을 실행하면, sqlalchemy.exc.NoReferencedColumnError: Could not initialize target column for ForeignKey ' users.id ' on table 'tasks': table 'users' has no column named 'id' 이런 오류가 나타납니다. 자꾸 자꾸 계속해서 다시 해봐도 제약조건에 이름을 넣으라고 나오고, 그것을 수정하면 users에 id가 없다는 둥 계속 똑같이 오류가 나옵니다. 해결 방법은 무엇일까요? 완전히 새로 해봐도 똑같은 오류만 계속 반복됩니다.
💡 질문하기 전에 먼저 확인해보세요! UnicodeDecodeError: 'cp949' codec can't decode byte 0xed in position 3465: illegal multibyte sequence 유니코드 관련에러가 발생합니다. utf-8 관련 설정에 문제가 있어보이는데, 해결방법을 구합니다. 별것을 다해본것 같은데 해결이 되질 않습니다. 코드는 알려주신데로 아래와 같이 수정했습니다. # /alembic.ini 파일 sqlalchemy.url = sqlite+aiosqlite:///./sql_app.db # /alembic/env.py 파일 import asyncio # 추가 from logging.config import fileConfig import os # 경로 작업 위해 추가 import sys # 경로 작업 위해 추가 from sqlalchemy import engine_from_config from sqlalchemy import pool # ✨ 추가: 비동기 엔진 설정을 위해 async_engine_from_config 사용 ✨ from sqlalchemy.ext.asyncio import async_engine_from_config from alembic import context # --- ✨ 추가: 프로젝트 루트 경로 추가 (env.py가 app 모듈을 찾도록) ✨ --- # env.py 파일의 부모 디렉토리의 부모 디렉토리 (즉, 프로젝트 루트)를 sys.path에 추가 sys.path.insert(0, os.path.realpath(os.path.join(os.path.dirname(__file__), ".."))) # -------------------------------------------------------------- # --- ✨ 추가: Base 및 모델 임포트 ✨ --- from app.database import Base # database.py의 Base 임포트 import app.sql_models.task # task 모델 모듈 임포트 (Base.metadata가 인식하도록) # 만약 다른 모델 파일들이 있다면 모두 임포트해주는 것이 안전합니다. # ----------------------------------------------------------------------------- # 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) # add your model's MetaData object here # for 'autogenerate' support # from myapp import mymodel # target_metadata = mymodel.Base.metadata # target_metadata = None # --- ✨변경: target_metadata 설정 ✨ --- target_metadata = Base.metadata # 우리의 모델 메타데이터 지정! # -------------------------------- # 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 do_run_migrations(connection): # context 설정 및 마이그레이션 실행 (run_sync 내부에서 호출될 함수) context.configure(connection=connection, target_metadata=target_metadata) with context.begin_transaction(): context.run_migrations() # --------------------------------------------------------------------------- # ... (run_migrations_offline 함수는 보통 그대로 둠) ... 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 = config.get_main_option("sqlalchemy.url") context.configure( url=url, target_metadata=target_metadata, literal_binds=True, dialect_opts={"paramstyle": "named"}, ) with context.begin_transaction(): context.run_migrations() # --- ✨ 변경: run_migrations_online 함수 비동기 방식으로 수정 ✨ --- async def run_migrations_online() -> None: """Run migrations in 'online' mode for an async application.""" # config 섹션에서 비동기 엔진 생성 connectable = async_engine_from_config( config.get_section(config.config_ini_section), prefix="sqlalchemy.", poolclass=pool.NullPool, future=True, # SQLAlchemy 2.0 스타일 사용 ) # 비동기적으로 DB 연결 async with connectable.connect() as connection: # 동기적인 마이그레이션 함수(do_run_migrations)를 # 비동기 연결의 run_sync 메서드 내에서 실행 await connection.run_sync(do_run_migrations) # 엔진 연결 종료 await connectable.dispose() # ----------------------------------------------------------------- ''' # ✨ 위의 것으로 수정 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. """ connectable = engine_from_config( config.get_section(config.config_ini_section, {}), prefix="sqlalchemy.", poolclass=pool.NullPool, ) with connectable.connect() as connection: context.configure( connection=connection, target_metadata=target_metadata ) with context.begin_transaction(): context.run_migrations() ''' if context.is_offline_mode(): run_migrations_offline() else: # ✨ run_migrations_online() # 아래로 변경 # 온라인 모드일 경우 비동기 함수 실행 asyncio.run(run_migrations_online())
안녕하세요. helloworld.py에 대해 print('hello world') 작성 후 저장, 디버깅을 했음에도 python helloworld.py 를 입력하면 'hello world'가 아닌 'Python'이 도출됩니다. py helloworld.py 를 입력하면 'hello world'가 제대로 나옵니다. 무엇이 잘못되었고 어떻게 수정할 수 있을까요?
김영한의 실전 데이터베이스 입문 - 모든 IT인을 위한 SQL 첫걸음(SQL부터 차근차근)
학습하는 분들께 도움이 되고, 더 좋은 답변을 드릴 수 있도록 질문 전에 다음을 꼭 확인해주세요. 1. 강의 내용과 관련된 질문을 남겨주세요. 2. 인프런의 질문 게시판과 자주 하는 질문(링크)을 먼저 확인해주세요. (자주 하는 질문 링크: https://bit.ly/3fX6ygx) 3. 질문 잘하기 메뉴얼(링크)을 먼저 읽어주세요. (질문 잘하기 메뉴얼 링크: https://bit.ly/2UfeqCG) 질문 시에는 위 내용은 삭제하고 다음 내용을 남겨주세요. ========================================= [질문 템플릿] 1. 강의 내용과 관련된 질문인가요? (예/아니오) 2. 인프런의 질문 게시판과 자주 하는 질문에 없는 내용인가요? (예/아니오) 3. 질문 잘하기 메뉴얼을 읽어보셨나요? (예/아니오) [질문 내용] 안녕하세요 쿼리를 작성하다 SELECT에 서브쿼리, 함수, 산술연산, 문자열 결합, CASE, DECODE 등 여러가지 작업을 진행하게 됩니다. 이 요소를 where절에 사용하려면 select 절에 입력한 내용을 그대로 입력해야 합니다. 이런 경우 저는 쿼리를 한번 감 싸서 where절에서 별칭을 사용해서 처리하는 방식으로 많이 작성하고 있습니다. 이런 방식이 안티패턴인지, 이런 방식으로 계속 작성해도 되는지 궁금합니다. SELECT customer_name, total_purchase FROM( SELECT customer_name, SUM(price * quantity) AS total_purchase FROM order_stat GROUP BY customer_name ) A WHERE A.total_purchase >= 400000; 이 케이스는 HAVING로 해결하면 되는 문제지만 이와 별개로(GROUP BY 존재여부 상관없이) 기존 SQL을 새로운 SELECT ~~ FROM (기존SQL) WHERE (별칭을 사용해서 제어) 이런 방식으로 사용해도 괜찮은 건지 궁금합니다.
동시성 제어는 분산락 원자적 연산 방식으로 해결한다고 설명해주셨는데, 레디스 분산락의 경우, 락을 획득하려는 클라이언트가 Redis의 Set 명령어를 사용하게 되는데, 이때 NX(Not eXists) 옵션을 통해 키가 존재하지 않을 때만 값을 설정하도록 하기 때문에, 이 연산은 원자적으로 수행된다고 합니다. 결론적으로 1, 2안 모두 원자적 연산을 의미하는것이라고 생각이 들어 헷갈리는데요..! 혹시 어떤 의도로 말씀해주신건지 설명해주실 수 있나요? 그리고 Redis를 예시로 들었을때, 레디스는 싱글 스레드 동작 방식이라서, 동시성 문제가 제어 된다고 하는데, 이 동시성 문제가 실제로 발생하는 경우는 어떻게 되는건지, redis 서버가 다중 노드일 때 발생하는건지 궁금합니다.