简体   繁体   English

未找到 cakephp 列:1054 user_id

[英]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 just id 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.

相关问题 找不到列:1054 CakePHP中的未知列'TaskTags.id' - Column not found: 1054 Unknown column 'TaskTags.id' in CakePHP SQLSTATE [42S22]:未找到列:1054 'where 子句'中的未知列 'majors.user_id'(SQL:从 `majors` 中选择 *,其中 `majors`.`user_id` = 1 - SQLSTATE[42S22]: Column not found: 1054 Unknown column 'majors.user_id' in 'where clause' (SQL: select * from `majors` where `majors`.`user_id` = 1 Cakephp。 SQLSTATE [42S22]:找不到列:1054“字段列表”中的未知列“ CalendarsClassification.id” - Cakephp. SQLSTATE[42S22]: Column not found: 1054 Unknown column 'CalendarsClassification.id' in 'field list' 用户ID与cakephp中的user_id不匹配 - User's ID doesn't match user_id in cakephp 错误:SQLSTATE[42S22]:未找到列:1054 CakePHP - Error: SQLSTATE[42S22]: Column not found: 1054 CakePHP 为什么user_id列为NULL? - Why user_id column is NULL? 未找到列:“字段列表”中的 1054 列“type_id”未知 - Column not found: 1054 Unknown column 'type_id' in 'field list' 未找到列:1054 'where 子句'中的未知列'id' Laravel 5.6 - Column not found: 1054 Unknown column 'id' in 'where clause' Laravel 5.6 找不到列:1054'on子句中的未知列'locations.id' - Column not found: 1054 Unknown column 'locations.id' in 'on clause 找不到列:1054“ where子句”中的未知列“ id”-Laravel - Column not found: 1054 Unknown column 'id' in 'where clause' - Laravel
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM