Nowe posty

Autor Wątek: Symfony: SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot  (Przeczytany 5722 razy)

Offline

  • Users
  • Prawie jak Guru
  • ****
  • Wiadomości: 272
    • Zobacz profil
Podczas pisania programu w symfony (projekt założony) pojawił się mnie komunikat. Co mogłem zrobić źle?

user:
  actAs: { Timestampable: ~ }
  columns:
    login:       { type: string (255), notnull: true, unique: true }
    password:    { type: string (255), notnull: true, unique: false }
    name:        { type: string (255), notnull: true, unique: false }
    lastname:    { type: string (255), notnull: true, unique: false }
    birth_date:  { type: date, notnull: false, unique: false }
    created_at:  { type: datetime, notnull: true, unique: false }
    updated_at:  { type: datetime, notnull: true, unique: false }
    email:       { type: string (255), notnull: true, unique: true }

news:
  actAs: { Timestampable: ~ }
  columns:
    description: { type: string (256) , notnull: true, unique: false }
    contents:    { type: string (65536) , notnull: true, unique: false }
    author_id:   { type: integer, notnull: true, unique: false }
    created_at:  { type: datetime, notnull: true, unique: false }
    updated_at:  { type: datetime, notnull: true, unique: false }
  relations:
    author:
      class: user
      local: author_id
      foreign: id
    tags:
      class: tag
      refClass: newstags
      local: id
      foreign: news_id

tag:
  actAs: { Timestampable: ~ }
  columns:
    name:        { type: string (255), notnull: true, unique: true }
    author_id:      { type: integer, notnull: true, unique: false }
    created_at:  { type: datetime, notnull: true, unique: false }
    updated_at:  { type: datetime, notnull: true, unique: false }
  relations:
    creator:
      class: user
      local: author_id
      foreign: id
    news:
      class: news
      refClass: newstags
      local: id
      foreign: tag_id

newstags:
  actAs: { Timestampable: ~ }
  columns:
    news_id:     { type: integer, notnull: true, unique: false }
    tag_id:      { type: integer, notnull: true, unique: false }
  relations:
    news:
      class: user
      local: news_id
      foreign: id
    tag:
      class: tag
      local: tag_id
      foreign: id

tasks:
  actAs:   { Timestampable: ~ }
  columns:
    name:        { type: string (256) , notnull: true, unique: false }
    description: { type: string (65536) , notnull: true, unique: false }
    orderer:     { type: string (256) , notnull: true, unique: false }
    deadline:    { type: date, notnull: true, unique: false }
    value:       { type: float,  notnull: true, unique: false }
    progress:    { type: integer, notnull: true, unique: false }
    progress_description: { type: string (256) , notnull: true, unique: false }

messages:
  actAs:   { Timestampable: ~ }
  columns:
    subject:     { type: string (256) , notnull: true, unique: false }
    contents:    { type: string (65536) , notnull: true, unique: false }
    author:      { type: string (256) , notnull: true, unique: false }
    created_at:  { type: datetime, notnull: true, unique: false }
    updated_at:  { type: datetime, notnull: true, unique: false }
500 | Internal Server Error | Doctrine_Connection_Mysql_Exception
SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails (`symfony`.`newstags`, CONSTRAINT `newstags_tag_id_tag_id` FOREIGN KEY (`tag_id`) REFERENCES `tag` (`id`))
stack trace
at ()
in SF_ROOT_DIR/lib/vendor/symfony/lib/plugins/sfDoctrinePlugin/lib/vendor/doctrine/Doctrine/Connection.php line 1082 ...
            $message .= sprintf('. Failing Query: "%s"', $query);

        }


        $exc  = new $name($message, (int) $e->getCode());

        if ( ! isset($e->errorInfo) || ! is_array($e->errorInfo)) {

            $e->errorInfo = array(null, null, null, null);

        }
at Doctrine_Connection->rethrowException(object('PDOException'), object('Doctrine_Connection_Statement'))
in SF_ROOT_DIR/lib/vendor/symfony/lib/plugins/sfDoctrinePlugin/lib/vendor/doctrine/Doctrine/Connection/Statement.php line 269 ...
at Doctrine_Connection_Statement->execute(array('1', '2', '2010-12-25 16:36:55', '2010-12-25 16:36:55'))
in SF_ROOT_DIR/lib/vendor/symfony/lib/plugins/sfDoctrinePlugin/lib/vendor/doctrine/Doctrine/Connection.php line 1042 ...
at Doctrine_Connection->exec('INSERT INTO newstags (news_id, id, created_at, updated_at) VALUES (?, ?, ?, ?)', array('1', '2', '2010-12-25 16:36:55', '2010-12-25 16:36:55'))
in SF_ROOT_DIR/lib/vendor/symfony/lib/plugins/sfDoctrinePlugin/lib/vendor/doctrine/Doctrine/Connection.php line 687 ...
at Doctrine_Connection->insert(object('newstagsTable'), array('news_id' => '1', 'id' => '2', 'created_at' => '2010-12-25 16:36:55', 'updated_at' => '2010-12-25 16:36:55'))
in SF_ROOT_DIR/lib/vendor/symfony/lib/plugins/sfDoctrinePlugin/lib/vendor/doctrine/Doctrine/Connection/UnitOfWork.php line 635 ...
at Doctrine_Connection_UnitOfWork->processSingleInsert(object('newstags'))
in SF_ROOT_DIR/lib/vendor/symfony/lib/plugins/sfDoctrinePlugin/lib/vendor/doctrine/Doctrine/Connection/UnitOfWork.php line 566 ...
at Doctrine_Connection_UnitOfWork->insert(object('newstags'))
in SF_ROOT_DIR/lib/vendor/symfony/lib/plugins/sfDoctrinePlugin/lib/vendor/doctrine/Doctrine/Connection/UnitOfWork.php line 81 ...
at Doctrine_Connection_UnitOfWork->saveGraph(object('newstags'))
in SF_ROOT_DIR/lib/vendor/symfony/lib/plugins/sfDoctrinePlugin/lib/vendor/doctrine/Doctrine/Connection/UnitOfWork.php line 456 ...
at Doctrine_Connection_UnitOfWork->saveAssociations(object('news'))
in SF_ROOT_DIR/lib/vendor/symfony/lib/plugins/sfDoctrinePlugin/lib/vendor/doctrine/Doctrine/Connection/UnitOfWork.php line 137 ...
at Doctrine_Connection_UnitOfWork->saveGraph(object('news'))
in SF_ROOT_DIR/lib/vendor/symfony/lib/plugins/sfDoctrinePlugin/lib/vendor/doctrine/Doctrine/Record.php line 1705 ...
at Doctrine_Record->save(object('Doctrine_Connection_Mysql'))
in SF_ROOT_DIR/lib/vendor/symfony/lib/form/addon/sfFormObject.class.php line 161 ...
at sfFormObject->doSave(object('Doctrine_Connection_Mysql'))
in SF_ROOT_DIR/lib/form/doctrine/base/BasenewsForm.class.php line 74 ...
at BasenewsForm->doSave(object('Doctrine_Connection_Mysql'))
in SF_ROOT_DIR/lib/vendor/symfony/lib/form/addon/sfFormObject.class.php line 130 ...
at sfFormObject->save()
in SF_ROOT_DIR/cache/admin/dev/modules/autoNews/actions/actions.class.php line 192 ...
at autoNewsActions->processForm(object('sfWebRequest'), object('newsForm'))
in SF_ROOT_DIR/cache/admin/dev/modules/autoNews/actions/actions.class.php line 102 ...
at autoNewsActions->executeUpdate(object('sfWebRequest'))
in SF_ROOT_DIR/lib/vendor/symfony/lib/action/sfActions.class.php line 60 ...
at sfActions->execute(object('sfWebRequest'))
in SF_ROOT_DIR/lib/vendor/symfony/lib/filter/sfExecutionFilter.class.php line 92 ...
at sfExecutionFilter->executeAction(object('newsActions'))
in SF_ROOT_DIR/lib/vendor/symfony/lib/filter/sfExecutionFilter.class.php line 78 ...
at sfExecutionFilter->handleAction(object('sfFilterChain'), object('newsActions'))
in SF_ROOT_DIR/lib/vendor/symfony/lib/filter/sfExecutionFilter.class.php line 42 ...
at sfExecutionFilter->execute(object('sfFilterChain'))
in SF_ROOT_DIR/lib/vendor/symfony/lib/filter/sfFilterChain.class.php line 53 ...
at sfFilterChain->execute()
in SF_ROOT_DIR/lib/vendor/symfony/lib/filter/sfRenderingFilter.class.php line 33 ...
at sfRenderingFilter->execute(object('sfFilterChain'))
in SF_ROOT_DIR/lib/vendor/symfony/lib/filter/sfFilterChain.class.php line 53 ...
at sfFilterChain->execute()
in SF_ROOT_DIR/lib/vendor/symfony/lib/controller/sfController.class.php line 233 ...
at sfController->forward('news', 'update')
in SF_ROOT_DIR/lib/vendor/symfony/lib/controller/sfFrontWebController.class.php line 48 ...
at sfFrontWebController->dispatch()
in SF_ROOT_DIR/lib/vendor/symfony/lib/util/sfContext.class.php line 170 ...
at sfContext->dispatch()
in SF_ROOT_DIR/web/admin_dev.php line 13 ...
symfony settings ...
request ...
response ...
user ...
global vars ...

symfony v.1.4.4 - php 5.2.14
for help resolving this issue, please visit http://www.symfony-project.org/.

Offline Tomcio Paluch

  • Users
  • Guru
  • *****
  • Wiadomości: 676
    • Zobacz profil
Symfony: SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot
« Odpowiedź #1 dnia: 2010-12-30, 18:38:48 »
Błąd jest na poziomie bazy danych. W skrócie: masz określoną relację pomiędzy kolumną b tabeli B a kolumną a tabeli A. Do tabeli B próbojesz wsadzić element, który nie istnieje w tabeli A co jest niezgodne ze zdefiniowaną relacją. Szczegóły masz w komunikacie "Integrity constraint violation ...".

PS. Nie ma to żadnego związku z linuxem, pomocy powinieneś szukać na stronach Symfony