DevNewb DevNewb - 2 months ago 22
MySQL Question

Error: SQLSTATE[42S22]: Column not found: 1054 CakePHP

I've been searching some answers for that problems that occurs while I'm trying to access a page baked with CakePHP, and I'm still getting this error :

Error: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'Billet. user_id' in 'field list'

Here's the query created by Cake

SELECT `Billet`.`id` AS `Billet__id`,
`Billet`.`created` AS `Billet__created`,
`Billet`.`updated` AS `Billet__updated`,
`Billet. user_id` AS `Billet__ user_id`,
`Billet`.`title` AS `Billet__title`,
`Billet`.`tags` AS `Billet__tags`,
`Billet`.`content` AS `Billet__content`,
`Users`.`id` AS `Users__id`,
`Users`.`username` AS `Users__username`,
`Users`.`password` AS `Users__password`,
`Users`.`name` AS `Users__name`,
`Users`.`lastname` AS `Users__lastname`,
`Users`.`birthdate` AS `Users__birthdate`,
`Users`.`email` AS `Users__email` FROM `billet`
`Billet` INNER JOIN `users` `Users` ON `Users`.`id` = (`Billet. user_id`) LIMIT 20 OFFSET 0


The code that does the query is directly baked by Cake, so I don't have any lines to show how the query's done.

Answer

You're missing ticks on this line, and you have an extra space in the AS name:

`Billet. user_id` AS `Billet__ user_id`,

It should be

`Billet`.`user_id` AS `Billet__user_id`,

Same goes for this line:

`Billet` INNER JOIN `users` `Users` ON `Users`.`id` = (`Billet. user_id`) LIMIT 20 OFFSET 0

which should be

`Billet` INNER JOIN `users` `Users` ON `Users`.`id` = (`Billet`.`user_id`) LIMIT 20 OFFSET 0
Comments