Welcome Guest, Not a member yet? Register   Sign In
Some error about models.
#1

[eluser]rockstyle[/eluser]
I've got absolutely no idea what this means:

Quote:Fatal error: Uncaught exception 'Doctrine_Connection_Mysql_Exception' with message 'SQLSTATE[HY000]: General error: 1452 Cannot add or update a child row: a foreign key constraint fails (`ci_doctrine`.`bank`, CONSTRAINT `bank_category_id_category_id` FOREIGN KEY (`category_id`) REFERENCES `category` (`id`))' in C:\xampplite\htdocs\ci_doctrine\system\application\plugins\doctrine\lib\Doctrine\Connection.php:1082 Stack trace: #0 C:\xampplite\htdocs\ci_doctrine\system\application\plugins\doctrine\lib\Doctrine\Connection\Statement.php(269): Doctrine_Connection->rethrowException(Object(PDOException), Object(Doctrine_Connection_Statement)) #1 C:\xampplite\htdocs\ci_doctrine\system\application\plugins\doctrine\lib\Doctrine\Connection.php(1042): Doctrine_Connection_Statement->execute(Array) #2 C:\xampplite\htdocs\ci_doctrine\system\application\plugins\doctrine\lib\Doctrine\Connection.php(687): Doctrine_Connection->exec('INSERT INTO ban...', Array) #3 C:\xampplite\htdocs\ci_doctrine\system\application\plugins\doctrine\lib\Doctrine\ in C:\xampplite\htdocs\ci_doctrine\system\application\plugins\doctrine\lib\Doctrine\Connection.php on line 1082

It happens when i'm trying to submit data from form. I think it's about models but i guess i made it right:
Code:
<?php
class Bank extends Doctrine_Record {

    public function setTableDefinition() {
        $this->hasColumn('title', 'string', 255);
        $this->hasColumn('description', 'string', 255);
        $this->hasColumn('category_id', 'integer', 4);
        $this->hasColumn('user_id', 'integer', 4);
        $this->hasColumn('url', 'string', 65535);
        $this->hasColumn('logo_url', 'string', 65535);
        $this->hasColumn('forum_url', 'string', 65535);
        $this->hasColumn('reason', 'string', 255);
    }

    public function setUp() {
        $this->actAs('Timestampable');
        $this->hasOne('Category', array(
            'local' => 'category_id',
            'foreign' => 'id'
        ));
        $this->hasOne('User', array(
            'local' => 'user_id',
            'foreign' => 'id'
        ));
    }

}
And category:
Code:
<?php
class Category extends Doctrine_Record {
    
    public function setTableDefinition() {
        $this->hasColumn('title', 'string', 255);
    }

    public function setUp() {
        $this->hasMany('Bank as Banks', array(
            'local' => 'id',
            'foreign' => 'category_id'
        ));
    }
}
Maybe relation is made wrong, i dunno...
#2

[eluser]danmontgomery[/eluser]
It's a MySQL error:

Quote:General error: 1452 Cannot add or update a child row: a foreign key constraint fails (`ci_doctrine`.`bank`, CONSTRAINT `bank_category_id_category_id` FOREIGN KEY (`category_id`) REFERENCES `category` (`id`))

I would guess that category.id isn't indexed or is indexed improperly
#3

[eluser]rockstyle[/eluser]
Damn, everything should be working, my model is working, here is phpmyadmin view:
http://img708.imageshack.us/img708/6849/relations.png

Indexation should work fine. Banks are indexing from 11 but it should'nt be the problem since it's working. Banks indexing are because i deleted rows and added once again by yaml file and It shouldn't be the issue.
#4

[eluser]danmontgomery[/eluser]
http://www.google.com/search?q=1452+Cann...aint+fails
#5

[eluser]rockstyle[/eluser]
Quote:whenever we create a foreign key column in an already existing table, there should be no values in that table or in otherway to say table should be empty.

I emptied the table and created the foreign key and then inserted the values back to the table

Any simple trick how to do this? The need for emptying the table and insering values every time i update scares the hell out of me. Not to mention performance...
#6

[eluser]theprodigy[/eluser]
Quote: #1 C:\xampplite\htdocs\ci_doctrine\system\application\plugins\doctrine\lib\Doctrine\Connection.php(1042): Doctrine_Connection_Statement->execute(Array)

#2 C:\xampplite\htdocs\ci_doctrine\system\application\plugins\doctrine\lib\Doctrine\Connection.php(687): Doctrine_Connection->exec(‘INSERT INTO ban…’, Array)
That's from the Stack Trace. It looks like you are trying to insert an array, and not a valid foreign key value.




Theme © iAndrew 2016 - Forum software by © MyBB