Symfony использует Doctrine и MySQL
Для 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, я хочу, чтобы все было максимально автоматизировано.
2 ответа
Я думаю, проблема в том, что вы используете одно и то же имя отношений дважды. Я нашел по крайней мере три: "UserState", "BuyBackModel", "BuyBackQuality", которые используются дважды в вашем schema.yml
Постарайтесь убедиться, что все ваши отношения уникальны, и попробуйте снова сгенерировать модель.
РЕДАКТИРОВАТЬ
Еще одна вещь, которую вы должны попробовать, это добавить имена классов в ваши отношения.
<...>
Relations:
class: foo
<...>
Я столкнулся с этой проблемой. Ни одна из этих идей не сработала, потому что я думаю, что это другая проблема.
Учение./symfony: build-схема
продолжает помещать старые отношения, которые больше не существуют, в мою схему. Так что либо у Symfony есть какое-то неясное место, где он кэшировал старые отношения, либо MySQL сообщает об отношениях, которые больше не существуют.
Я думаю, что Symfony тянет отношения из других источников, таких как формы или фильтры. Я собираюсь попробовать очистить базовые каталоги для форм и фильтров.
Хм. Нашел это. Внешние ключи не удаляются в MySQL, в моем GUI, в WorkBench. Вы должны удалить индексы тоже.
Лучшее решение. Резервное копирование вашей базы данных структуры и содержания. И пересоздайте базу данных, если у вашего GUI-инструмента для MySQL возникли проблемы.