CodeIgniter and Doctrine: Base table or view not found
I'm following the documentation almost word for word, except for two adjustments which I believe are corrections.
First adjustment: I eliminate the redundant DIRECTORY_SEPARATOR
in system/application/doctrine.php
:
//this produces "...system/application//fixtures"
$config = array('data_fixtures_path' => dirname(__FILE__) . DIRECTORY_SEPARATOR . '/fixtures',
//Replaced with:
$config = array('data_fixtures_path' => dirname(__FILE__) . DIRECTORY_SEPARATOR . 'fixtures',
The resulting paths appear correct.
Second adjustment: The generated models (e.g. models/User.php
) don't seem to load the base models that extend Doctrine_Record
, so I add an explicit require()
call to each model like so:
require('generated/BaseUser.php');
class User extends BaseUser { ... }
So, my current problem: When it comes time to build the tables for the first time:
$ ./doctrine build-all-reload
build-all-reload - Are you sure you wish to drop your databases? (y/n)
y
build-all-reload - Successfully dropped database for connection named 'mydb'
build-all-reload - Successfully created database for connection named 'mydb'
build-all-reload - Created tables successfully
SQLSTATE[42S02]: Base table or view not found: 1146 Table 'mydb.user' doesn't exist
Doctrine seems to happily empty tables, drop tables, drop databases, and create databases, but I can't figure out why it won't create tables. It clearly says Created tables successfully
, but SHOW TABLES;
returns "No tables found in database."
Doctrine is using the same MySQL user that I am, which has ALL PRIVILEGES
.
Any开发者_运维知识库 ideas why Doctrine can't create tables? Hopefully I'm just blind and/or dumb.
Alternatively, is there I way I can just produce a file of SQL CREATE statements based on my yaml schema or models that I can run on my own to debug this issue?
Maybe you have already done it but not mentioning it but you MAY be missing all the required "loading" commands. Using require
is not the best solution here.
Doctrine_Core::loadModels(realpath(dirname(__FILE__) . '/..') . DIRECTORY_SEPARATOR . 'models');
This needs to be done for each directory that holds Doctrine related model files (models, basemodels, tables,...) since it does not work recursively. I had the very same problem and defining loadModels
for each of my directories did the trick.
Maybe table name "user" can be a reason in this specific case. Try to set other name for table.
精彩评论