본문 바로가기

Web_Application/.NET Core

Scaffold-DbContext - Build failed, errors



개발 환경 win 10, vs 2019, .net core 2.1 , mysql 8.0

패키지관리자콘솔

실행

PM> Scaffold-DbContext "Server={{host}};Port={{port}};Database={{db_name}};Uid={{user_id}};Pwd={{password}};" MySql.Data.EntityFrameworkCore -OutputDir Models



에러메세지

Build failed.

> 접속정보는 정상이라는 가정하에 프로젝트를 처음 생성하고 빌드 과정을 거치지 않고 바로 실행했을때 발생합니다.

Models 폴더에 db_name 의

The following file(s) already exist in directory 
{{source_path}}\Models: {{db_name}}Context.cs. Use the Force flag to overwrite these files.

> 해당 폴더에 동일한 파일이 존재합니다. 지우고 다시 실행하면 정상적으로 생성 됩니다.

 

Unable to identify the primary key for table '{{db_name}}.{{table_name}}'.
Unable to generate entity type for table '{{db_name}}.{{table_name}}'.

> 테이블 컬럼에 pk를 지정해줘야합니다. pk가 없는 테이블은 개발자가 직접 클래스를 구현해줘야합니다.