Wheels.NoPrimaryKey

188 views
Skip to first unread message

Jeffrey A Craig

unread,
Feb 13, 2011, 3:15:53 PM2/13/11
to ColdFusion on Wheels
Working thru the "Beginner Tutorial: Hello Database" I am getting this
error message.

The db table does have an id field that is set as an identity field in
MS SQL server

Wheels.NoPrimaryKey

No primary key exists on the users table.
Suggested action

Set an appropriate primary key on the users table.
Error location

Line 5 in controllers\Users.cfc

3: <cffunction name="new">
4:
5: <cfset user = model("user").new()>
6:
7: </cffunction>

Tag context

Error thrown on line 137 in wheels\model\initialization.cfm
- called from line 1 in root.cfm
- called from line 355 in wheels\global\internal.cfm
- called from line 598 in wheels\global\internal.cfm
- called from line 174 in wheels\global\cfml.cfm
- called from line 27 in wheels\global\cfml.cfm
- called from line 207 in wheels\global\public.cfm
- called from line 5 in controllers\Users.cfc
- called from line 174 in wheels\global\cfml.cfm
- called from line 85 in wheels\controller\processing.cfm
- called from line 60 in wheels\controller\processing.cfm
- called from line 285 in wheels\dispatch\request.cfm
- called from line 1 in wheels\index.cfm
- called from line 1 in index.cfm
- called from line 1 in wheels\events\onrequest.cfm

Nathan Stanford II

unread,
Feb 14, 2011, 8:05:24 AM2/14/11
to cfwh...@googlegroups.com
Hey Jeff,

If I understand the error, you are getting this because the database does not have a primary key. Also, may sure the primary key is int and an auto-incrementing value. 

Nathan Stanford II

tpet...@gmail.com

unread,
Feb 14, 2011, 8:57:07 AM2/14/11
to ColdFusion on Wheels
if you can't change the database scheme in order to mark a column as a
primary key, you can always tell wheels to use a specific column by
using setPrimaryKey()

http://cfwheels.org/docs/1-1/function/setPrimaryKey

On Feb 14, 8:05 am, Nathan Stanford II <nathan.stanfo...@gmail.com>
wrote:

Nathan Stanford II

unread,
Feb 14, 2011, 9:18:53 AM2/14/11
to cfwh...@googlegroups.com
Yea I forgot you don't always have access to that. Pretty awesome to have that ability! Have to remember that one.

Nathan Stanford II

Jeffrey A Craig

unread,
Feb 14, 2011, 9:46:50 AM2/14/11
to ColdFusion on Wheels
Thank you for the reply.

Yeah, that is what the error says but that is not the case.

I've added the table to different dbs; tried other tables in different
dbs. Tried stopping IIS and CF services; rebooted the computer
thinking there may be a caching problem.

So far none of the id int identity fields in MS SQL are recognized.

I've only had yesterday to install and start digging thru the code to
get an idea of how it works so it is probably something basic I have
missed.

But the setting the id field in MS SQL is not the issue.

On Feb 14, 7:05 am, Nathan Stanford II <nathan.stanfo...@gmail.com>
wrote:

Andy Bellenie

unread,
Feb 14, 2011, 10:47:42 AM2/14/11
to cfwh...@googlegroups.com
Apologies, but to be absolutely clear, it's not having them set to
identity that's important, the id field must be set as the primary
key.

If you add <cffunction name="init">
<cfset setPrimaryKey('id")>
</cffunction>

to the model file, does it fix the error?

/ Andy

> --
> You received this message because you are subscribed to the Google Groups "ColdFusion on Wheels" group.
> To post to this group, send email to cfwh...@googlegroups.com.
> To unsubscribe from this group, send email to cfwheels+u...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/cfwheels?hl=en.
>
>

Jeffrey A Craig

unread,
Feb 14, 2011, 11:41:19 AM2/14/11
to ColdFusion on Wheels
I wasn't sure which file you were referring to.

I added the code to /models/Model.cfc and that does make it work.

<!---
This is the parent model file that all your models should extend.
You can add functions to this file to make them globally available in
all your models.
Do not delete this file.
--->
<cfcomponent extends="Wheels">
<cffunction name="init">
<cfset setPrimaryKey('id')>
</cffunction>
</cfcomponent>

I was expecting a default recognition of the id field as the identity
field. Should that have happened?

Chris Peters

unread,
Feb 14, 2011, 11:45:08 AM2/14/11
to cfwh...@googlegroups.com
Internally, Wheels uses <cfdbinfo> to see which column(s) are set as the primary key. Your problem is more than likely that the id column is not defined as the primary key.

You may have it set to be identity and auto-increment, but it also needs to be the primary key.

tpet...@gmail.com

unread,
Feb 14, 2011, 11:48:40 AM2/14/11
to ColdFusion on Wheels
@jeff,

actually you put the declaration in the target model's init. so in
your case you would put it in the User model init

<!--- User.cfc --->
<cfcomponent extends="Model">
<cffunction name="init">
<cfset setPrimaryKey('id')>
</cffunction>
</cfcomponent>

Jeffrey A Craig

unread,
Feb 14, 2011, 12:25:21 PM2/14/11
to ColdFusion on Wheels
Bingo!! Lights came on.

It was passing right by me -- primary key vs identity.



Reply all
Reply to author
Forward
0 new messages