简体   繁体   English

Database_Exception [1146]:表'kohana.userdetailses'不存在

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

相关问题 Database_Exception [1146]:表&#39;database.roles&#39;不存在[从`roles`显示全部列] - Database_Exception [ 1146 ]: Table 'database.roles' doesn't exist [ SHOW FULL COLUMNS FROM `roles` ] 1146表不存在 - 1146 Table doesn't exist Kohana-Database_Exception [2]:mysql_connect() - Kohana - Database_Exception [ 2 ]: mysql_connect() 如何使用Kohana 3 ORM处理Database_Exception - How to treat Database_Exception with Kohana 3 ORM Kohana数据库错误:新创建的表不存在 - Kohana database error: newly-created table doesn't exist Laravel Spatie 权限 - 未找到基表或视图:1146 表“my_database.models”不存在 - Laravel Spatie Permissions - Base table or view not found: 1146 Table 'my_database.models' doesn't exist Laravel:未找到基表或视图:1146表'database.pages不存在 - Laravel: Base table or view not found: 1146 Table 'database.pages doesn't exist 错误1146:mysql Phpmyadmin中的表&#39;#__content&#39;不存在&#39; - Error 1146: table '#__content' doesn't exist' in mysql Phpmyadmin SQLSTATE[42S02]:未找到基表或视图:1146 表“My_database_Name.posts”不存在 - SQLSTATE[42S02]: Base table or view not found: 1146 Table 'My_database_Name.posts' doesn't exist 创建表后出现MySQL错误消息:#1146-表&#39;&#39;phpmyadmin.pma_table_uiprefs&#39;不存在 - MySQL error message after creating table: #1146 - Table ''phpmyadmin.pma_table_uiprefs' doesn't exist
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM