Symfony 使用 Doctrine 和 MySQL

发布于 2024-09-14 20:52:10 字数 10322 浏览 9 评论 0原文

为了让 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 symfonydoctrine: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 的新手,我希望一切都尽可能自动化。

For schema.yml to work with relations, do you have to InnoDB? Here is my schema:

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

But the database is MyISAM. So when I run: php symfony doctrine:build --model I get a bunch of these:

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

I am brand new to Symfony, so I could be screwing up the schema, please check.

Here is what it does actually load:

>> 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

But before this there are a bunch of Undefined Index Notices, I don't want to go any further, I have scrapped the application a few times now and tried a lot of things, but I thought this schema would work. The guy who controls the database creation around here has his heart set on MyISAM, so I don't want to try and make him change it if there is something I can do to work around it. The sad thing is, I have scripts to create the database, but when I generate the schema off of my already in place structure it leaves out the relations, and since I am new to symfony, I want everything as automated as possible.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

心欲静而疯不止 2024-09-21 20:52:10

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

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

编辑

您应该尝试的另一件事是向您的关系添加类名称。

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

I think the problem is that you are using the same Relations name twice.
I found at least three: "UserState", "BuyBackModel", "BuyBackQuality" which are used twice in your schema.yml

Try to make sure all your relations are unique, and try generating the model again.

EDIT

Another thing you should try, is adding class names to your Relations.

<...>
Relations:
   class: foo
<...>
烟雨凡馨 2024-09-21 20:52:10

我遇到了这个问题。这些想法都不起作用,因为我认为这是另一个问题。

./symfony 原则:构建模式

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

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

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

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

I ran into this problem. None of these ideas worked because I think it's another problem.

./symfony doctrine:build-schema

keeps putting old relations that no longer exist, into my schema. So either Symfony has some obscure place it has cached old relations, or MySQL is reporting relations that no longer exist.

I think Symfony is pulling in the relations from other sources like forms or filters. I am going to try clearing out the base directories for forms and filters.

Hmm. Found it. The foreign keys aren't getting deleted in MySQL, in my GUI, in WorkBench. You have to deleted the indexes too.

Best solution. Backup your database structure and content. And recreate the database if your GUI tool for MySQL is having problems.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文