Very idiotic problem, insert database submission failed, always go integrityerror error, no error message, thought plug in, get a long time, and finally printed the error message
(Sqlite3. Integrityerror) Samples.file_type May is NULL [sql:u ' INSERT into samples (file_size, File_type, MD5, CRC32, SHA1, SHA SHA512, Ssdeep) VALUES (?,?,?,?,?,?,?,?) [Parameters: (+, none, ' hello ', ' crc32 ', ' sha1 ', ' sha256 ', ' sha512 ', none)]
Tip for File_type cannot be empty, but when I insert the File_type setting is empty
The first is to pay attention to the printing error message; the second set of non-empty data must not be transmitted Null,python the current use of less easy to forget
From SQLAlchemy import Column, Integer, stringfrom sqlalchemy import create_enginefrom sqlalchemy.ext.declarative Import Declarative_basefrom sqlalchemy import Text, indexfrom sqlalchemy.exc import Sqlalchemyerror, Integrityerrorfrom Sqlalchemy.orm Import sessionmakerbase = Declarative_base () class Sample (Base): "" "Submitted files details." " __tablename__ = "samples" id = column (integer (), primary_key=true) file_size = Column (Integer (), Nullable=false)File_type = Column (Text (), Nullable=false) MD5 = column (string (+), nullable=false) crc32 = Column (String (8), nullable=false) SHA1 = Column (string (+), nul Lable=false) sha256 = Column (String (), nullable=false) sha512 = Column (string (+), nullable=false) Ssdeep = Co Lumn (String (255), nullable=true) __table_args__ = Index ("Hash_index", "MD5", "CRC32", "SHA1", "Sha256", "sha512", Unique=true), Def __repr__ (self): return "<sample (' {0} ', ' {1} ') >". Format (Self.id, self . sha256) def __init__ (self, MD5, CRC32, SHA1, SHA256, sha512, File_size, File_type=none, Ssdeep=none): SELF.MD5 = MD5 SELF.SHA1 = SHA1 Self.crc32 = CRC32 self.sha256 = sha256 self.sha512 = s ha512 self.file_size = file_size if File_type:self.file_type = File_type if ssdeep: Self.ssdeep = Ssdeepengine = Create_engine ("sqlite:///cuckoo.db", echo=true) #返回连接引擎metadata = Base.metadatametadat A.create_all (engine) #连Connect or create #sample_mike = sample ("Hello", "CRC32", "SHA1", "sha256", "sha512", +, None, none) #非空数据不能传空
Sample_mike = Sample ("Hello", "CRC32", "SHA1", "sha256", "sha512",, "AA", None)
Session = Sessionmaker (bind=engine) session = Session () Session.add (sample_mike) #数据库会话
Session.commit () #提交
Print E
Print E
Finally on the Internet to see a more useful tool SQLite, view DB database
SQLite, db, insert.py download Http://files.cnblogs.com/files/aliflycoris/db.zip
Commit error in Python SQLAlchemy--item non-empty cannot insert empty data