【问题标题】:Symfony using Doctrine and MySQLSymfony 使用 Doctrine 和 MySQL
【发布时间】:2010-08-18 14:30:17
【问题描述】:

为了使用 schema.yml 来处理关系,你必须使用 InnoDB 吗?这是我的架构:

BuybackStatus:
  connection: doctrine
  tableName: buyback_statuses
  columns:
    id:
      type: integer(4)
      fixed: false
      unsigned: true
      primary: true
      autoincrement: true
    label:
      type: string()
      fixed: false
      unsigned: false
      primary: false
      notnull: true
      autoincrement: false
  relations:
    BuybackStatus:
      local: id
      foreign: status_id
      type: one
Country:
  connection: doctrine
  tableName: countries
  columns:
    id:
      type: integer(4)
      fixed: false
      unsigned: true
      primary: true
      autoincrement: true
    label:
      type: string()
      fixed: false
      unsigned: false
      primary: false
      notnull: true
      autoincrement: false
    code:
      type: string()
      fixed: false
      unsigned: false
      primary: false
      notnull: true
      autoincrement: false
  relations:
    StateCountry:
      local: id
      foreign: state_id
      type: one
    UserCountry:
      local: id
      foreign: state_id
      type: one
Manufacture:
  connection: doctrine
  tableName: manufactures
  columns:
    id:
      type: integer(4)
      fixed: false
      unsigned: true
      primary: true
      autoincrement: true
    label:
      type: string()
      fixed: false
      unsigned: false
      primary: false
      notnull: true
      autoincrement: false
  relations:
    PhoneModelManufacture:
      local: id
      foreign: manufacture_id
      type: one
PhoneModel:
  connection: doctrine
  tableName: phone_models
  columns:
    id:
      type: integer(4)
      fixed: false
      unsigned: true
      primary: true
      autoincrement: true
    manufacture_id:
      type: integer(4)
      fixed: false
      unsigned: false
      primary: false
      notnull: true
      autoincrement: false
    label:
      type: string()
      fixed: false
      unsigned: false
      primary: false
      notnull: true
      autoincrement: false
    buyback_price:
      type: 'decimal(6, 2)'
      fixed: false
      unsigned: false
      primary: false
      notnull: true
      autoincrement: false
  relations:
    PhoneModelManufacture:
      onDelete: CASCADE
      local: manufacture_id
      foreign: id
    BuybackModel:
      local: id
      foreign: model_id
      type: one
Quality:
  connection: doctrine
  tableName: qualities
  columns:
    id:
      type: integer(4)
      fixed: false
      unsigned: true
      primary: true
      autoincrement: true
    label:
      type: string()
      fixed: false
      unsigned: false
      primary: false
      notnull: true
      autoincrement: false
    percent:
      type: 'decimal(6, 2)'
      fixed: false
      unsigned: false
      primary: false
      notnull: true
      autoincrement: false
  relations:
    BuybackQuality:
      local: id
      foreign: quality_id
      type: one
State:
  connection: doctrine
  tableName: states
  columns:
    id:
      type: integer(4)
      fixed: false
      unsigned: true
      primary: true
      autoincrement: true
    label:
      type: string()
      fixed: false
      unsigned: false
      primary: false
      notnull: true
      autoincrement: false
    code:
      type: string()
      fixed: false
      unsigned: false
      primary: false
      notnull: true
      autoincrement: false
    country_id:
      type: integer(4)
      fixed: false
      unsigned: false
      primary: false
      notnull: true
      autoincrement: false
  relations:
    StateCountry:
      onDelete: CASCADE
      local: country_id
      foreign: id
      foreignAlias: StateCountries
    UserState:
      local: id
      foreign: state_id
      type: one
User:
  connection: doctrine
  tableName: users
  columns:
    id:
      type: integer(4)
      fixed: false
      unsigned: true
      primary: true
      autoincrement: true
    fname:
      type: string()
      fixed: false
      unsigned: false
      primary: false
      notnull: true
      autoincrement: false
    lname:
      type: string()
      fixed: false
      unsigned: false
      primary: false
      notnull: true
      autoincrement: false
    phone:
      type: string()
      fixed: false
      unsigned: false
      primary: false
      notnull: true
      autoincrement: false
    email:
      type: string()
      fixed: false
      unsigned: false
      primary: false
      notnull: true
      autoincrement: false
    password:
      type: string()
      fixed: false
      unsigned: false
      primary: false
      notnull: true
      autoincrement: false
    street:
      type: string()
      fixed: false
      unsigned: false
      primary: false
      notnull: true
      autoincrement: false
    city:
      type: string()
      fixed: false
      unsigned: false
      primary: false
      notnull: true
      autoincrement: false
    state_id:
      type: integer(4)
      fixed: false
      unsigned: false
      primary: false
      notnull: true
      autoincrement: false
    country_id:
      type: integer(4)
      fixed: false
      unsigned: false
      primary: false
      notnull: true
      autoincrement: false
  relations:
    UserState:
      onDelete: CASCADE
      local: state_id
      foreign: id
      type: one
    UserCountry:
      onDelete: CASCADE
      local: country_id
      foreign: id
      type: one
    BuybackUser:
      local: id
      foreign: user_id
      type: many
BuybackPhone:
  connection: doctrine
  tableName: buyback_phones
  columns:
    id:
      type: integer(4)
      fixed: false
      unsigned: true
      primary: true
      autoincrement: true
    user_id:
      type: integer(4)
      fixed: false
      unsigned: false
      primary: false
      notnull: true
      autoincrement: false
    model_id:
      type: integer(4)
      fixed: false
      unsigned: false
      primary: false
      notnull: true
      autoincrement: false
    quality_id:
      type: integer(4)
      fixed: false
      unsigned: false
      primary: false
      notnull: true
      autoincrement: false
    buyback_status_id:
      type: integer(4)
      fixed: false
      unsigned: false
      primary: false
      notnull: true
      autoincrement: false
    amount_quoted:
      type: 'decimal(6, 2)'
      fixed: false
      unsigned: false
      primary: false
      notnull: true
      autoincrement: false
    amount_paid:
      type: 'decimal(6, 2)'
      fixed: false
      unsigned: false
      primary: false
      notnull: true
      autoincrement: false
    makes_calls:
      type: integer(1)
      fixed: false
      unsigned: false
      primary: false
      notnull: true
      autoincrement: false
    water_damage:
      type: integer(1)
      fixed: false
      unsigned: false
      primary: false
      notnull: true
      autoincrement: false
    has_charger:
      type: integer(1)
      fixed: false
      unsigned: false
      primary: false
      notnull: true
      autoincrement: false
    has_battery:
      type: integer(1)
      fixed: false
      unsigned: false
      primary: false
      notnull: true
      autoincrement: false
  relations:
    BuybackUser:
      onDelete: CASCADE
      local: user_id
      foreign: id
      type: one
    BuybackModel:
      onDelete: CASCADE
      local: model_id
      foreign: id
      type: one
    BuybackQuality:
      onDelete: CASCADE
      local: quality_id
      foreign: id
      type: one
    BuybackStatus:
      onDelete: CASCADE
      local: buyback_status_id
      foreign: id
      type: one

但数据库是 MyISAM。所以当我运行时:php symfony doctrine:build --model 我得到了一堆这些:

Notice: Undefined index:  class in /home/kacie/cellphone/lib/vendor/symfony/lib/plugins/sfDoctrinePlugin/lib/vendor/doctrine/Doctrine/Import/Builder.php on line 672

我是 Symfony 的新手,所以我可能搞砸了架构,请检查。

这是它实际加载的内容:

>> tokens    /home/kacie/cellphone/lib/model/doctrine/PhoneModel.class.php
>> tokens    /home/kacie/cellphone/lib/model/doctrine/PhoneModelTable.class.php
>> tokens    /home/kacie/cellphone/lib/model/doctrine/BuybackStatus.class.php
>> tokens    /home/kacie/cellphone/lib/model/doctrine/BuybackPhoneTable.class.php
>> tokens    /home/kacie/cellphone/lib/model/doctrine/Manufacture.class.php
>> tokens    /home/kacie/cellphone/lib/model/doctrine/CountryTable.class.php
>> tokens    /home/kacie/cellphone/lib/model/doctrine/Country.class.php
>> tokens    /home/kacie/cellphone/lib/model/doctrine/ManufactureTable.class.php
>> tokens    /home/kacie/cellphone/lib/model/doctrine/UserTable.class.php
>> tokens    /home/kacie/cellphone/lib/model/doctrine/Quality.class.php
>> tokens    /home/kacie/cellphone/lib/model/doctrine/BuybackPhone.class.php
>> tokens    /home/kacie/cellphone/lib/model/doctrine/BuybackStatusTable.class.php
>> tokens    /home/kacie/cellphone/lib/model/doctrine/User.class.php
>> tokens    /home/kacie/cellphone/lib/model/doctrine/State.class.php
>> tokens    /home/kacie/cellphone/lib/model/doctrine/StateTable.class.php
>> tokens    /home/kacie/cellphone/lib/model/doctrine/QualityTable.class.php
>> tokens    /home/kacie/cellphone/lib/model/doctrine/base/BaseState.class.php
>> tokens    /home/kacie/cellphone/lib/model/doctrine/base/BaseBuybackStatus.class.php
>> tokens    /home/kacie/cellphone/lib/model/doctrine/base/BaseUser.class.php
>> tokens    /home/kacie/cellphone/lib/model/doctrine/base/BaseBuybackPhone.class.php
>> tokens    /home/kacie/cellphone/lib/model/doctrine/base/BaseManufacture.class.php
>> tokens    /home/kacie/cellphone/lib/model/doctrine/base/BasePhoneModel.class.php
>> tokens    /home/kacie/cellphone/lib/model/doctrine/base/BaseQuality.class.php
>> tokens    /home/kacie/cellphone/lib/model/doctrine/base/BaseCountry.class.php
>> autoload  Resetting application autoloaders
>> file-     /home/kacie/cellphone/cache/frontend/prod/config/config_autoload.yml.php

但是在此之前有一堆未定义的索引通知,我不想再进一步了,我现在已经废弃了几次应用程序并尝试了很多东西,但我认为这个架构可以工作。控制这里的数据库创建的人一心想着 MyISAM,所以如果我能做些什么来解决它,我不想让他改变它。可悲的是,我有创建数据库的脚本,但是当我从已有的结构中生成模式时,它会忽略关系,而且由于我是 symfony 的新手,所以我希望一切都尽可能自动化。

【问题讨论】:

    标签: mysql symfony1 schema yaml


    【解决方案1】:

    我认为问题在于您两次使用相同的关系名称。 我发现至少三个:“UserState”、“BuyBackModel”、“BuyBackQuality”,它们在您的 schema.yml 中使用了两次

    尝试确保所有关系都是唯一的,然后再次尝试生成模型。

    编辑

    您应该尝试的另一件事是将类名添加到您的关系中。

    <...>
    Relations:
       class: foo
    <...>
    

    【讨论】:

    • 我继续做了一个 InnoDB 并基于它制作了一个模式。您应该使用类名作为关系名称。像这样:States: ... relations: Countries: local: country_id foreign: id type: one Users: local: id foreign: state_id type: many
    【解决方案2】:

    我遇到了这个问题。这些想法都没有奏效,因为我认为这是另一个问题。

    ./symfony 学说:构建模式

    不断将不再存在的旧关系放入我的架构中。因此,要么 Symfony 有一些模糊的地方缓存了旧的关系,要么 MySQL 报告了不再存在的关系。

    我认为 Symfony 正在从其他来源(如表单或过滤器)中提取关系。我将尝试清除表单和过滤器的基本目录。

    嗯。找到了。在 MySQL、我的 GUI 和 WorkBench 中,外键没有被删除。您也必须删除索引。

    最佳解决方案。备份您的数据库结构和内容。如果 MySQL 的 GUI 工具出现问题,请重新创建数据库。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-01-01
      • 1970-01-01
      • 2018-08-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多