Django 에러 Unable to import 'django.db'

hyereen·2021년 7월 25일
1

장고 프로젝트 생성 뒤, 필요한 앱 별 모델을 만든다.

아래는 내가 강의들으면서 생성한 models.py 코드이다.

from django.db import models

class Fcuser(models.Model):
    email = models.EmailField(verbose_name='이메일')
    password = models.CharField(max_length=64, verbose_name='비밀번호')
    register_date = models.DateTimeField(auto_now_add=True, verbose_name='등록날짜')

    class Meta:
        db_table = 'fastcampus_fcuser'
        verbose_name = '사용자'
        verbose_name_plural = '사용자'

이제 makemigrations하고 migrate 해서 실제 테이블 생성 하기 전에 settings.py 에 생성한 앱 추가해야 된다. fcuser라는 앱을 만들었으므로 맨 아래에 추가했다.

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'fcuser'
]

그러나 아래와 같은 에러가 났다.

Unable to import 'django.db'

해결방법

  1. .vscode 내에 settings.json 파일 추가하기
    출처: https://stackoverflow.com/questions/47483933/using-pylint-with-visual-studio-code

settings.json

{
    "python.pythonPath": "C:\\Users\\(User Name)\\AppData\\Local\\Programs\\Python\\Python37\\python.exe",
    "python.linting.pylintPath": "c:\\(Project Directory Name)\\(Virtual Environment Name)\\lib\\site-packages\\",
    "python.linting.pylintEnabled": false,
    "python.linting.enabled": true
}
  1. "python.linting.pylintEnabled": false한 이유
    출처: https://stackoverflow.com/questions/43272664/error-message-linter-pylint-is-not-installed

위와 같이 설정 후 다시 python manage.py makemigrations 하면 마이그레이션 된다.

profile
안녕하세요. 피드백은 언제나 감사합니다.

0개의 댓글