Highlighted

Field 'blogCategoryid' doesn't have a default value

Explorer ,
Dec 07, 2015

Copy link to clipboard

Copied

Adding new category names are showing the following error.  Also, it is not allowing me to edit the names at all.  Please help resolve this.  Thank you.

Field 'blogCategoryid' doesn't have a default value

Root cause :java.sql.SQLException: Field 'blogCategoryid' doesn't have a default value

The error occurred in C:/ColdFusion11/cfusion/wwwroot/learncfinaweek/chapter1solution/admin/content/blog/editcategory.cfm: line 33

<cfset ormFlush() />

editCategories.cfm:

<cfimport taglib="../../customTags" prefix="ct" />

<ct:securityCheck redirectPage="#cgi.script_name#"/>

<cfparam name="url.id" default="0" />

<cfparam name="form.submitted" default="0" />

<cfparam name="form.id" default="0" />

<cfparam name="form.name" default="" />

                <cfparam name="form.categories" default="" />

<cfset errorBean = createObject('learncfinaweek.chapter1solution.admin.cfc.errorBean').init() />

<cfif form.submitted>

    <!--- check if data is valid--->

    <cfif !errorBean.hasErrors()>

        <cfif val(form.id)>

            <!--- Edit Entity  --->

            <cfset blogCategory = EntityLoad('BlogCategory',form.id,true) />

            <cfset blogCategory.name = form.name />

        <cfelse>

            <!--- Create Entity --->

            <cfset blogCategory = EntityNew('BlogCategory') />

            <cfset blogCategory.name = form.name />

        </cfif>

        <cfset entitySave(BlogCategory) />

        <cfset ormFlush() />

        <cflocation url="listcategory.cfm?message=#urlencodedformat('Blog Category Saved')#" addtoken="false" />

    </cfif>

</cfif>

<cfif val(url.id)>

    <!--- Get Entity Data --->

    <cfset blogCategory = EntityLoad('BlogCategory',url.id,true) />

    <cfset form.name = blogCategory.name />

</cfif>

<cfoutput>

    <ct:layout section="blog">

        <ct:navigation section="blog" active="post"/>

        <div class="span10">

            <cfif val(url.id)>

                <h2>Edit Category</h2>

            <cfelse>

                <h2>Add Category</h2>

            </cfif>

            <cfif errorBean.hasErrors()>

                <div class="alert alert-error">

                    <strong>Error</strong><br />

                    The following errors occured:

                    <ul>

                        <cfloop array="#errorBean.getErrors()#" index="error">

                            <li>#error.message#</li>

                        </cfloop>

                    </ul>

                </div>

            </cfif>

            <form class="form-horizontal" action="#cgi.script_name#" method="post">

                <div class="control-group">

                    <label class="control-label" for="title">Name</label>

                    <div class="controls">

                        <input type="text" id="name" name="name" value="#form.name#">

                    </div>

                </div>

                <div class="control-group">

                    <div class="controls">

                        <button type="submit" class="btn btn-primary">Save</button>

                    </div>

                </div>

                <input type="hidden" name="submitted" value="1" />

                <input type="hidden" name="id" value="#url.id#" />

            </form>

        </div>

    </ct:layout>

</cfoutput>

blogPost.cfc page:

component persistent="true" {

    Property name="id" column="blogpostid" fieldtype="id" generator="increment";

    Property name="title" ormtype="text";

    Property name="summary" ormtype="text";

    Property name="body" ormtype="text";

    Property name="dateposted" ormtype="timestamp";

    Property name="createdDateTime" ormtype="timestamp";

    Property name="modifiedDateTime" ormtype="timestamp";

    Property name="deleted" ormtype="boolean";

    Property name="comments" singularname="comment" fieldtype="one-to-many" cfc="blogComment" fkcolumn="blogpostid" cascade="all";

    Property name="categories" fieldtype="one-to-many" cfc="blogPostCategory" fkcolumn="blogPostid";

    public string function getCategoryIDs() {

        var categoryList = '';

        if ( hasCategories() ) {

            for (var categoryPost in getCategories() ) {

                    categoryList = listAppend( categoryList, categoryPost.blogCategory.id);

            }

        }

        return categoryList;

    }

    public string function getCategoryNames(){

        var categoryList = '';

        if(hasCategories()){

            for(var categoryPost in getCategories()){

                categoryList = listAppend(categoryList, categoryPost.blogCategory.name,', ');

            }

        }

        return categoryList;

        }

}

editBlogPost.cfm page:

<cfimport taglib="../../customTags" prefix="ct" />

<ct:securityCheck redirectPage="#cgi.script_name#"/>

<cfparam name="url.id" default="0" />

<cfparam name="form.submitted" default="0" />

<cfparam name="form.id" default="0" />

<cfparam name="form.title" default="" />

<cfparam name="form.summary" default="" />

<cfparam name="form.body" default="" />

<cfparam name="form.datePosted" default="" />

    <cfparam name="form.categories" default="" />

<cfset errorBean = createObject('learncfinaweek.chapter1solution.admin.cfc.errorBean').init() />

<cfif form.submitted>

    <!--- check if data is valid--->

    <cfif !len(trim(form.title))>

        <cfset errorBean.addError('Title is required','title') />

    </cfif>

    <cfif !len(trim(form.summary))>

        <cfset errorBean.addError('A summary is required','startDate') />

    </cfif>

    <cfif !len(trim(form.body))>

        <cfset errorBean.addError('You need to provide a body','details') />

    </cfif>

    <cfif !len(trim(form.datePosted))>

        <cfset errorBean.addError('You need to provide a release date','details') />

    </cfif>

    <!--- Only process if there are no errors --->

    <cfif !errorBean.hasErrors()>

        <cfif val(form.id)>

            <!--- Edit Entity  --->

            <cfset blogPost = EntityLoad('BlogPost',form.id,true) />

            <cfset blogPost.title = form.title />

            <cfset blogPost.summary = form.summary />

            <cfset blogPost.body = form.body />

            <cfset blogPost.dateposted = form.dateposted />

            <cfset blogPost.modifiedDateTime = now() />

                <cfloop array="#blogPost.getCategories()#" index="category">

                    <cfset entityDelete(category) />

                </cfloop>

            <cfelse>

                <!--- Create Entity --->

                <cfset blogPost = EntityNew('BlogPost') />

                <cfset blogPost.title = form.title />

                <cfset blogPost.summary = form.summary />

                <cfset blogPost.body = form.body />

                <cfset blogPost.dateposted = form.dateposted />

                <cfset blogPost.createdDateTime = now() />

        </cfif>

        <cfset entitySave(BlogPost) />

        <cfloop list="#form.categories#" index="categoryID">

            <!--- Add Category to Entity --->

            <cfset blogPostCategory = EntityNew('blogPostCategory') />

            <cfset blogCategory = EntityLoad('blogCategory',categoryID,true) />

            <cfset blogPostCategory.blogCategory=blogCategory />

            <cfset blogPostcategory.blogpost=blogpost />

            <cfset entitySave(blogPostCategory) />

        </cfloop>

        <cfset ormFlush() />

        <cflocation url="listblogpost.cfm?message=#urlencodedformat('Blog Post Saved')#" addtoken="false" />

    </cfif>

</cfif>

<cfif val(url.id)>

    <!--- Get Entity Data --->

    <cfset blogPost = EntityLoad('BlogPost',url.id,true) />

    <cfset form.id = blogPost.id />

    <cfset form.title = blogPost.title />

    <cfset form.summary = blogPost.summary />

    <cfset form.body = blogPost.body />

    <cfset form.dateposted = blogPost.dateposted />

    <cfset form.categories = blogPost.categoryids />

        <!---<cfset form.categories = blogPost.categoryNames />--->

</cfif>

<cfset categories = entityLoad('BlogCategory' ) />

<cfoutput>

    <ct:layout section="blog">

        <ct:navigation section="blog" active="post"/>

        <div class="span10">

            <cfif val(url.id)>

                <h2>Edit Blog Post</h2>

            <cfelse>

                <h2>Add Blog Post</h2>

            </cfif>

            <cfif errorBean.hasErrors()>

                <div class="alert alert-error">

                    <strong>Error</strong><br />

                    The following errors occured:

                    <ul>

                        <cfloop array="#errorBean.getErrors()#" index="error">

                            <li>#error.message#</li>

                        </cfloop>

                    </ul>

                </div>

            </cfif>

            <form class="form-horizontal" action="#cgi.script_name#" method="post">

                <div class="control-group">

                    <label class="control-label" for="title">Title</label>

                    <div class="controls">

                        <input type="text" id="title" name="title" value="#form.title#">

                    </div>

                </div>

                <div class="control-group">

                    <label class="control-label" for="title">Summary</label>

                    <div class="controls">

                        <textarea rows="6" id="summary" name="summary" class="input-xlarge">#form.summary#</textarea>

                    </div>

                </div>

                <div class="control-group">

                    <label class="control-label" for="title">Body</label>

                    <div class="controls">

                        <textarea rows="3" id="body" name="body" class="wysiwyg">#form.body#</textarea>

                    </div>

                </div>

                <div class="control-group">

                    <label class="control-label" for="details">Publish Date</label>

                    <div class="controls">

                        <input type="text" id="datePosted" name="datePosted" class="datepicker" value="#dateFormat(form.datePosted,'mm/dd/yyyy')#">

                    </div>

                </div>

                <div class="control-group">

                    <label class="control-label" for="details">Categories</label>

                    <div class="controls">

                            <label class="checkbox">

                            <cfloop array="#categories#" index="category">

                                <input type="checkbox" name="Categories" value="#category.id#" <cfif listfind(form.categories,category.id)>checked</cfif>>#category.name#<br />

                            </cfloop>

                        </label>

                    </div>

                </div>

                <div class="control-group">

                    <div class="controls">

                        <button type="submit" class="btn btn-primary">Save</button>

                    </div>

                </div>

                <input type="hidden" name="submitted" value="1" />

                <input type="hidden" name="id" value="#url.id#" />

            </form>

        </div>

    </ct:layout>

</cfoutput>

I got it working.  It was the DB.  Open up MySQL Workbench and highlight and right click all of the tables.  Choose DROP.  Then to repopulate the tables for learncfinaweek, run the script import_mysql, available online.  The site works great now.  Thank You Jesus.

TOPICS
Getting started

Views

634

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more

Field 'blogCategoryid' doesn't have a default value

Explorer ,
Dec 07, 2015

Copy link to clipboard

Copied

Adding new category names are showing the following error.  Also, it is not allowing me to edit the names at all.  Please help resolve this.  Thank you.

Field 'blogCategoryid' doesn't have a default value

Root cause :java.sql.SQLException: Field 'blogCategoryid' doesn't have a default value

The error occurred in C:/ColdFusion11/cfusion/wwwroot/learncfinaweek/chapter1solution/admin/content/blog/editcategory.cfm: line 33

<cfset ormFlush() />

editCategories.cfm:

<cfimport taglib="../../customTags" prefix="ct" />

<ct:securityCheck redirectPage="#cgi.script_name#"/>

<cfparam name="url.id" default="0" />

<cfparam name="form.submitted" default="0" />

<cfparam name="form.id" default="0" />

<cfparam name="form.name" default="" />

                <cfparam name="form.categories" default="" />

<cfset errorBean = createObject('learncfinaweek.chapter1solution.admin.cfc.errorBean').init() />

<cfif form.submitted>

    <!--- check if data is valid--->

    <cfif !errorBean.hasErrors()>

        <cfif val(form.id)>

            <!--- Edit Entity  --->

            <cfset blogCategory = EntityLoad('BlogCategory',form.id,true) />

            <cfset blogCategory.name = form.name />

        <cfelse>

            <!--- Create Entity --->

            <cfset blogCategory = EntityNew('BlogCategory') />

            <cfset blogCategory.name = form.name />

        </cfif>

        <cfset entitySave(BlogCategory) />

        <cfset ormFlush() />

        <cflocation url="listcategory.cfm?message=#urlencodedformat('Blog Category Saved')#" addtoken="false" />

    </cfif>

</cfif>

<cfif val(url.id)>

    <!--- Get Entity Data --->

    <cfset blogCategory = EntityLoad('BlogCategory',url.id,true) />

    <cfset form.name = blogCategory.name />

</cfif>

<cfoutput>

    <ct:layout section="blog">

        <ct:navigation section="blog" active="post"/>

        <div class="span10">

            <cfif val(url.id)>

                <h2>Edit Category</h2>

            <cfelse>

                <h2>Add Category</h2>

            </cfif>

            <cfif errorBean.hasErrors()>

                <div class="alert alert-error">

                    <strong>Error</strong><br />

                    The following errors occured:

                    <ul>

                        <cfloop array="#errorBean.getErrors()#" index="error">

                            <li>#error.message#</li>

                        </cfloop>

                    </ul>

                </div>

            </cfif>

            <form class="form-horizontal" action="#cgi.script_name#" method="post">

                <div class="control-group">

                    <label class="control-label" for="title">Name</label>

                    <div class="controls">

                        <input type="text" id="name" name="name" value="#form.name#">

                    </div>

                </div>

                <div class="control-group">

                    <div class="controls">

                        <button type="submit" class="btn btn-primary">Save</button>

                    </div>

                </div>

                <input type="hidden" name="submitted" value="1" />

                <input type="hidden" name="id" value="#url.id#" />

            </form>

        </div>

    </ct:layout>

</cfoutput>

blogPost.cfc page:

component persistent="true" {

    Property name="id" column="blogpostid" fieldtype="id" generator="increment";

    Property name="title" ormtype="text";

    Property name="summary" ormtype="text";

    Property name="body" ormtype="text";

    Property name="dateposted" ormtype="timestamp";

    Property name="createdDateTime" ormtype="timestamp";

    Property name="modifiedDateTime" ormtype="timestamp";

    Property name="deleted" ormtype="boolean";

    Property name="comments" singularname="comment" fieldtype="one-to-many" cfc="blogComment" fkcolumn="blogpostid" cascade="all";

    Property name="categories" fieldtype="one-to-many" cfc="blogPostCategory" fkcolumn="blogPostid";

    public string function getCategoryIDs() {

        var categoryList = '';

        if ( hasCategories() ) {

            for (var categoryPost in getCategories() ) {

                    categoryList = listAppend( categoryList, categoryPost.blogCategory.id);

            }

        }

        return categoryList;

    }

    public string function getCategoryNames(){

        var categoryList = '';

        if(hasCategories()){

            for(var categoryPost in getCategories()){

                categoryList = listAppend(categoryList, categoryPost.blogCategory.name,', ');

            }

        }

        return categoryList;

        }

}

editBlogPost.cfm page:

<cfimport taglib="../../customTags" prefix="ct" />

<ct:securityCheck redirectPage="#cgi.script_name#"/>

<cfparam name="url.id" default="0" />

<cfparam name="form.submitted" default="0" />

<cfparam name="form.id" default="0" />

<cfparam name="form.title" default="" />

<cfparam name="form.summary" default="" />

<cfparam name="form.body" default="" />

<cfparam name="form.datePosted" default="" />

    <cfparam name="form.categories" default="" />

<cfset errorBean = createObject('learncfinaweek.chapter1solution.admin.cfc.errorBean').init() />

<cfif form.submitted>

    <!--- check if data is valid--->

    <cfif !len(trim(form.title))>

        <cfset errorBean.addError('Title is required','title') />

    </cfif>

    <cfif !len(trim(form.summary))>

        <cfset errorBean.addError('A summary is required','startDate') />

    </cfif>

    <cfif !len(trim(form.body))>

        <cfset errorBean.addError('You need to provide a body','details') />

    </cfif>

    <cfif !len(trim(form.datePosted))>

        <cfset errorBean.addError('You need to provide a release date','details') />

    </cfif>

    <!--- Only process if there are no errors --->

    <cfif !errorBean.hasErrors()>

        <cfif val(form.id)>

            <!--- Edit Entity  --->

            <cfset blogPost = EntityLoad('BlogPost',form.id,true) />

            <cfset blogPost.title = form.title />

            <cfset blogPost.summary = form.summary />

            <cfset blogPost.body = form.body />

            <cfset blogPost.dateposted = form.dateposted />

            <cfset blogPost.modifiedDateTime = now() />

                <cfloop array="#blogPost.getCategories()#" index="category">

                    <cfset entityDelete(category) />

                </cfloop>

            <cfelse>

                <!--- Create Entity --->

                <cfset blogPost = EntityNew('BlogPost') />

                <cfset blogPost.title = form.title />

                <cfset blogPost.summary = form.summary />

                <cfset blogPost.body = form.body />

                <cfset blogPost.dateposted = form.dateposted />

                <cfset blogPost.createdDateTime = now() />

        </cfif>

        <cfset entitySave(BlogPost) />

        <cfloop list="#form.categories#" index="categoryID">

            <!--- Add Category to Entity --->

            <cfset blogPostCategory = EntityNew('blogPostCategory') />

            <cfset blogCategory = EntityLoad('blogCategory',categoryID,true) />

            <cfset blogPostCategory.blogCategory=blogCategory />

            <cfset blogPostcategory.blogpost=blogpost />

            <cfset entitySave(blogPostCategory) />

        </cfloop>

        <cfset ormFlush() />

        <cflocation url="listblogpost.cfm?message=#urlencodedformat('Blog Post Saved')#" addtoken="false" />

    </cfif>

</cfif>

<cfif val(url.id)>

    <!--- Get Entity Data --->

    <cfset blogPost = EntityLoad('BlogPost',url.id,true) />

    <cfset form.id = blogPost.id />

    <cfset form.title = blogPost.title />

    <cfset form.summary = blogPost.summary />

    <cfset form.body = blogPost.body />

    <cfset form.dateposted = blogPost.dateposted />

    <cfset form.categories = blogPost.categoryids />

        <!---<cfset form.categories = blogPost.categoryNames />--->

</cfif>

<cfset categories = entityLoad('BlogCategory' ) />

<cfoutput>

    <ct:layout section="blog">

        <ct:navigation section="blog" active="post"/>

        <div class="span10">

            <cfif val(url.id)>

                <h2>Edit Blog Post</h2>

            <cfelse>

                <h2>Add Blog Post</h2>

            </cfif>

            <cfif errorBean.hasErrors()>

                <div class="alert alert-error">

                    <strong>Error</strong><br />

                    The following errors occured:

                    <ul>

                        <cfloop array="#errorBean.getErrors()#" index="error">

                            <li>#error.message#</li>

                        </cfloop>

                    </ul>

                </div>

            </cfif>

            <form class="form-horizontal" action="#cgi.script_name#" method="post">

                <div class="control-group">

                    <label class="control-label" for="title">Title</label>

                    <div class="controls">

                        <input type="text" id="title" name="title" value="#form.title#">

                    </div>

                </div>

                <div class="control-group">

                    <label class="control-label" for="title">Summary</label>

                    <div class="controls">

                        <textarea rows="6" id="summary" name="summary" class="input-xlarge">#form.summary#</textarea>

                    </div>

                </div>

                <div class="control-group">

                    <label class="control-label" for="title">Body</label>

                    <div class="controls">

                        <textarea rows="3" id="body" name="body" class="wysiwyg">#form.body#</textarea>

                    </div>

                </div>

                <div class="control-group">

                    <label class="control-label" for="details">Publish Date</label>

                    <div class="controls">

                        <input type="text" id="datePosted" name="datePosted" class="datepicker" value="#dateFormat(form.datePosted,'mm/dd/yyyy')#">

                    </div>

                </div>

                <div class="control-group">

                    <label class="control-label" for="details">Categories</label>

                    <div class="controls">

                            <label class="checkbox">

                            <cfloop array="#categories#" index="category">

                                <input type="checkbox" name="Categories" value="#category.id#" <cfif listfind(form.categories,category.id)>checked</cfif>>#category.name#<br />

                            </cfloop>

                        </label>

                    </div>

                </div>

                <div class="control-group">

                    <div class="controls">

                        <button type="submit" class="btn btn-primary">Save</button>

                    </div>

                </div>

                <input type="hidden" name="submitted" value="1" />

                <input type="hidden" name="id" value="#url.id#" />

            </form>

        </div>

    </ct:layout>

</cfoutput>

I got it working.  It was the DB.  Open up MySQL Workbench and highlight and right click all of the tables.  Choose DROP.  Then to repopulate the tables for learncfinaweek, run the script import_mysql, available online.  The site works great now.  Thank You Jesus.

TOPICS
Getting started

Views

635

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Dec 07, 2015 0
Explorer ,
Dec 08, 2015

Copy link to clipboard

Copied

I got it working.  It was the DB.  Open up MySQL Workbench and highlight and right click all of the tables.  Choose DROP.  Then to repopulate the tables for learncfinaweek, run the script import_mysql, available online.  The site works great now.  Thank You Jesus.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Dec 08, 2015 2