[英]cakephp Column not found: 1054 user_id
I have made a table:我做了一个表:
CREATE TABLE IF NOT EXISTS `users` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`username` varchar(255) NOT NULL,
`password` varchar(255) NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `username` (`username`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=2 ;
Now when I use bin\\cake bake everything goes fine but when I go to the index view.现在,当我使用 bin\\cake bake 时一切正常,但是当我转到索引视图时。 I get an error Column not found: 1054 Champ 'Users.user_id'
我收到一个错误Column not found: 1054 Champ 'Users.user_id'
This is the query that is made by Cakephp:这是由 Cakephp 进行的查询:
SELECT Users.id AS `Users__id`, Users.username AS `Users__username`, Users.password AS `Users__password` FROM users Users WHERE Users.user_id = :c0 LIMIT 1
I don't know what I did wrong but the tutorial blog suggested to not use user_id
but just id
as primary key.我不知道我做错了什么,但是教程博客建议不要使用user_id
而只是id
作为主键。
My model does have the displayField listed as user_id but it still doesn't work:我的模型确实将 displayField 列为 user_id 但它仍然不起作用:
$this->table('users');
$this->displayField('user_id');
$this->primaryKey('user_id');
I don't know what I did wrong but the tutorial blog suggested to not use
user_id
but justid
as primary key.我不知道我做错了什么,但是教程博客建议不要使用user_id
而只是id
作为主键。
* emphasis mine * 强调我的
So then why do you use it?那么,为什么你用了吗? There is no user_id
column in your table, so what you are seeing is the expected behavior.您的表中没有user_id
列,因此您看到的是预期的行为。
The primary key is named id
, so refer to that column instead of user_id
.主键名为id
,因此请参考该列而不是user_id
。 Also you don't want your display field to be the PK, using the username makes more sense.此外,您不希望您的显示字段成为 PK,使用用户名更有意义。
$this->table('users');
$this->displayField('username');
$this->primaryKey('id');
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.