#sqlite3 db.sqlite3
sqlite>.database
sqlite>.table
sqlite>.schema (테이블명)
sqlite>insert into 테이블명 values('var1','var2' .... );
sqlite>select * from 테이블명 (조건);
sqlite>delete from 테이블명 (조건);
sqlite>drop table 테이블명 (조건);
여러 컬럼을 대상으로 중복 데이터를 제외
여러 컬럼을 대상으로 중복 데이터를 제외하려면 여러 컬럼 값의 조합이 일치하는 데이터를 제외다. 예를 들어 앞에서 사용한 product 테이블에서 name 컬럼과 color 컬럼의 데이터를 조회할 때 중복 데이터를 제외하고 조회하는 경우는 다음과 같이 작성한다.
select distinct name, color from product;
sqlite> select distinct name, color from product; name color ---------- ---------- Mouse White Pen Green Mouse Black NotePC Black Display Yellow sqlite>
1. 장고 내 models.py 에서 테이블 만들기
class Malicious(models.Model):
id = models.TextField(max_length = 128)
writer = models.TextField(max_length = 128)
validForm = models.TextField(max_length = 20)
validUtil = models.TextField(max_length = 16)
importance = models.TextField(max_length = 5)
confirmYn = models.TextField(max_length = 3)
sharedScope = models.TextField(max_length = 32)
sharedList = models.TextField(max_length = 128)
category = models.TextField(max_length =256)
url = models.TextField(primary_key=True, max_length = 512)
class Meta:
db_table = 'malicious'
@@에러발생 : You are trying to add a non-nullable field 'category' to register without a default; we can't do that (the database needs something to popul ate existing rows). Please select a fix:
해결방안
1.null=True 설정
2.default='' 설정
3.__0001.py 파일 삭제
4. sqlte3 들어가서 테이블 지우고 다시 생성
'django' 카테고리의 다른 글
[django] csv export (0) | 2021.04.16 |
---|---|
Boundfield.py widget typeerror (0) | 2021.01.18 |
django restframework 사용하기 (0) | 2020.12.22 |
django wagtail - 1. python가상환경 설정 및 wagtail 설치 (0) | 2020.09.08 |