2017-04-02 4 views
0

は、私はこのエラーを解決/逃れたと思った。しかし、今こだわっています私のdb.pyコード:。。のweb2py:IntegrityErrorは( 'NULL制約が故障していない:post.message

Post = db.define_table('post', 
         Field('message', 'text', requires=IS_NOT_EMPTY(), notnull=False), 
         Field('answers', 'text', requires=IS_NOT_EMPTY(), notnull=False), 
         auth.signature 
     ) 
Post.is_active.readable=False 
Post.is_active.writeable=False 

コントローラ:

@ auth.requires_login()私の見解で

def index(): 
    db.post.answers.writable=False 
    db.post.answers.readable=False 
    form = SQLFORM(post, formstyle='divs') 
    if form.process().accepted: 
     pass 
    messages = db(post).select(orderby=~post.created_on) 
    .......code 
    #after several codes in now need to post a message to answers field, WITHOUT using a form in the view page 
    db.post.insert(answers=report) 

{{for msg in messages:}} 
code 
{{=msg.message}} 
{{report from answers field}} 

私の問題は、エラーが続いていることです。IntegrityError( 'NOT NULL制約に失敗しました:post.message

このエラーを解決するにはどうすればよいですか?外部ツールを(DALは、そのような制約を削除することはできません)が必要NOT NULL制約を除去するように、データベーステーブルは元々、後で影響を及ぼさないであろうnotnull=Falseにモデルを変更すること、notnull=Trueで作成された場合 種類

+0

あなたは最初に 'notnull = True'を持っていましたか? – Anthony

+0

はい私はそれを持っていた – wakamdr

+0

http://www.mail-archive.com/[email protected]/msg12879.html .....このポストはトリックをした......デフォルト= – wakamdr

答えて

0

に関して。

あなたのコメントで示唆しているように、フィールドのデフォルト値を空の文字列のように設定することもできますが、実際にはnull値を許可する場合は、代わりにデータベース管理ツールを使用してデータベーススキーマからの制約。

関連する問題