在CakePHP中缺少数据库表,我遵循了惯例并尝试了一切 [英] Missing database table in CakePHP, I've followed the conventions and tried everything

查看:223
本文介绍了在CakePHP中缺少数据库表,我遵循了惯例并尝试了一切的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序与其他模型配合使用,但由于某些原因,当我尝试保存到Vote模型时,无法连接到数据库表。我已经在这里了几天,我觉得我已经尝试了一切!



这里是我的控制器VoteController.php调用模型可读性):

 <?php 

类VoteController扩展AppController {

var $ uses = array('Track','Vote');

function upvote(){
$ this-> autoRender = false;
$ User = $ this-> auth();
if($ User){
$ track_id = @ $ this-> params ['id'];
$ this-> Vote-> upvote($ track_id,$ User ['User'] ['id']);
}
}

}

?>

这里是模型vote.php:

 <?php 

App :: uses('AppModel','Model');

class Vote extends AppModel {

var $ name ='Vote';

function upvote($ id,$ user_id){
$ VoteObject = array('Vote'=> array(
'u_id'=> $ user_id,
't_id'=> $ id,
'upvote'=> 1,
'downvote'=> 0

$ this-> save($ VoteObject);
}

}

?>

当然,在我的数据库中, t_id,upvote和downvote。
一切执行后,我收到此错误:



缺少数据库表



错误:



我试过删除tmp中的文件,以及重命名一切,打印出查询等,我可以似乎得到任何地方。



<$>

解决方案

p $ p> App :: uses('AppModel','Model');

并将其添加到类

  var $ useTable ='vote'; 

它似乎尝试使用正确的名称。所以这可能不是一个问题。您可以验证您的数据源设置是否正确。


My app works with other models, but for some reason the "Vote" model cannot connect to the db table when I try to save to it. I've been at this for a couple days and I feel like I've tried everything!

here is my controller VoteController.php that calls the model (edited down for readability):

<?php

class VoteController extends AppController {

    var $uses = array('Track', 'Vote');

    function upvote() {
        $this->autoRender = false;
        $User = $this->auth();
        if ($User) {
            $track_id = @$this->params['id'];
            $this->Vote->upvote($track_id, $User['User']['id']);
        }
    }

}

?>

here is the model vote.php:

<?php

App::uses('AppModel', 'Model');

class Vote extends AppModel {

    var $name = 'Vote';

    function upvote($id, $user_id) {
        $VoteObject = array('Vote' => array(
                'u_id' => $user_id,
                't_id' => $id,
                'upvote' => 1,
                'downvote' => 0
                ));
        $this->save($VoteObject);
    }

}

?>

And of course, in my database, I have a table "votes" with columns id, u_id, t_id, upvote, and downvote. After everything executes, I get this error:

Missing Database Table

Error: Table votes for model Vote was not found in datasource default.

I've tried deleting the files in tmp, as well as renaming everything, printing out queries, etc, and I can't seem to get anywhere. Any help would be greatly appreciated!

解决方案

try removing this line

App::uses('AppModel', 'Model');

and adding this to the class

var $useTable = 'votes';

It looks like it's trying to use the correct name. so that might not be an issue. Can you verify that your data source is setup correctly.

这篇关于在CakePHP中缺少数据库表,我遵循了惯例并尝试了一切的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆