[英]Database_Exception [ 1146 ]: Table 'kohana.userdetailses' doesn't exist
This is my Controller 这是我的控制器
userdetails.php userdetails.php
<?php defined('SYSPATH') or die('No direct script access.');
class Controller_Userdetails extends Controller {
public function action_index() {
$view = new View('userdetails/index');
$this->response->body($view);
}
public function action_add() {
$userdetails = new Model_Userdetails();
$view = new View('userdetails/adddetails');
$view->set("userdetails", $userdetails);
$this->response->body($view);
}
model is 模型是
userdetails.php userdetails.php
<?php defined('SYSPATH') or die('No direct script access.');
class Model_Userdetails extends ORM {
}
userinfo.sql userinfo.sql
CREATE TABLE `kohana`.`userinfo` (
`id` int unsigned NOT NULL AUTO_INCREMENT,
`first_name` varchar(100) DEFAULT NULL,
`last_name` varchar(100) DEFAULT NULL,
`email` varchar(100) DEFAULT NULL,
`description` text,
PRIMARY KEY (`id`)
);
I am newly learning php and kohana.I am using kohana 3.2 version.I am following this tutorial to create,edit,update and delete data in database.I tried with above code,i am getting this error 我正在学习php和kohana。我正在使用kohana 3.2版本。我正在按照本教程创建,编辑,更新和删除数据库中的数据。我尝试了上面的代码,但出现此错误
"Database_Exception [ 1146 ]: Table 'kohana.userdetailses' doesn't exist [ SHOW FULL COLUMNS FROM `userdetailses` ]"
need some help to solve this. 需要一些帮助来解决这个问题。
Kohana guesses the table name if $_table_name
is not set. 如果未设置
$_table_name
则Kohana会猜测表名称。 It pluralizes the model name as most of the time a model describes a single object, and the table describes a lot of them. 多数情况下,模型描述单个对象时,它会使模型名称具有多种形式,而表中描述了很多名称。
EDIT : 编辑 :
I saw you actually named your table userinfo
and the model userdetails
. 我看到您实际上将表命名为
userinfo
,并将模型命名为userdetails
。 If that is what you want: 如果那是您想要的:
class Model_Userdetails {
protected $_table_name = 'userinfo';
........
}
Or alternatively rename the model to Model_Userinfo
, or the table to userdetails
and: 或者将模型重命名为
Model_Userinfo
,或者将表重命名为userdetails
并:
--- END EDIT --- --- 结束编辑 ---
In your case it would seem most appropiate to: 您的情况似乎最适合:
class Model_Userdetails {
protected $_table_name = 'userdetails';
........
}
Offcourse, you could alternatively rename your class to Model_Userdetail
so that the table name will be guessed as userdetails
当然,您也可以将您的班级重命名为
Model_Userdetail
以便将表名猜测为userdetails
UPDATE : 更新 :
Even though Kohana should guess these as well (ie SHOW FULL COLUMNS FOR table
or sth), this might resolve the property not found
error as discussed below in the comments. 即使Kohana也应该猜测这些(即
SHOW FULL COLUMNS FOR table
或某事),这可能会解决property not found
错误,如下面的注释中所述。
protected $_table_columns = array(
'id' => array('type' => 'int'),
'firstname' => array('type' => 'string'),
....... // repeat for all columns
);
Update: 更新:
There is a typo in your PHP code: deScription
. 您的PHP代码中有一个错字:
deScription
。 Anyway, it is a good habit to define the table columns as this will save you an extra query every time a model is initialized for the first time. 无论如何,定义表列是一个好习惯,因为这将在每次首次初始化模型时为您节省额外的查询。 Along with some validation stuff which can take parameters from the array (eg the
description
of type TEXT
is more or less not restricted in length, but you might want to limit it to say 2000 characters) 以及一些可以从数组中获取参数的验证内容(例如,
description
TEXT
类型的description
或多或少没有限制长度,但您可能希望将其限制为2000个字符)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.