我的问题是为什么我在运行propel diff
时遇到错误
vendor\bin\propel diff In Table.php line 796: Table "product_product_category" contains a foreign key to table "product_category" but does not have a reference to foreign primary key "place_id"
。
这是我的schema.xml:
` <table name="product" phpName="Product" identifierQuoting="true">
<column name="id" type="integer" required="true" primaryKey="true" autoIncrement="true"/>
<column name="name" type="varchar" size="32" required="true" phpName="Name"/>
<column name="description" type="varchar" size="500" required="true" phpName="Description"/>
<column name="photo_name" type="varchar" size="32" required="false" phpName="PhotoName"/>
<column name="is_active" type="BOOLEAN" required="true" defaultValue="false" phpName="Active" phpType = "boolean"/>
<column name="price" type="integer" required="true" phpName="Price"/>
<column name="place_id" type="integer" required="true" phpName="CurrentPlaceId"/>
<foreign-key foreignTable="place" phpName="CurrentPlace" refPhpName="CurrentPlaceProduct" onDelete="CASCADE">
<reference local="place_id" foreign="id"/>
</foreign-key>
<column name="measurement_type_id" type="integer" required="true" phpName="CurrentMeasurementTypeId"/>
<foreign-key foreignTable="measurement_type" phpName="CurrentMeasurementType" refPhpName="CurrentMeasurementTypeProduct">
<reference local="measurement_type_id" foreign="id"/>
</foreign-key>
<column name="measurement" type="integer" defaultValue="0" phpName="Measurement"/>
<behavior name="timestampable" />
<behavior name="query_cache" />
</table>
<table name="place" phpName="Place" identifierQuoting="true">
<column name="id" type="integer" required="true" primaryKey="true" autoIncrement="true"/>
<column name="name" type="varchar" size="32" required="true" phpName="Name"/>
<column name="alt_name" type="varchar" size="32" required="true" phpName="AltName"/>
<column name="description" type="varchar" size="1000" required="false" phpName="Description"/>
<column name="logo_name" type="varchar" size="32" required="false" phpName="LogoName"/>
<column name="cover_name" type="varchar" size="32" required="false" phpName="CoverName"/>
<column name="min_order_amount" type="integer" required="true" phpName="MinOrderAmount"/>
<column name="delivery_cost" type="integer" required="true" phpName="DeliveryCost"/>
<column name="is_active" type="BOOLEAN" required="true" defaultValue="false" phpName="Active" phpType = "boolean"/>
<column name="address" type="varchar" size="100" required="true" phpName="Address"/>
<column name="address_coordinates" type="ARRAY" required="false" phpName="AddressCoordinates"/>
<column name="around_the_clock" type="BOOLEAN" required="true" defaultValue="false" phpName="AroundTheClock" phpType = "boolean"/>
<column name="week_days" type="ARRAY" required="true" phpName="WeekDays"/>
<column name="work_start_time" type="TIME" required="false" phpName="WorkStartTime"/>
<column name="work_end_time" type="TIME" required="false" phpName="WorkEndTime"/>
<column name="phones" type="ARRAY" required="true" phpName="Phones"/>
<column name="place_admin_id" type="integer" required="true" phpName="CurrentPlaceAdminId"/>
<foreign-key foreignTable="user" phpName="CurrentPlaceAdmin" refPhpName="CurrentPlaceAdminPlace" onDelete="CASCADE">
<reference local="place_admin_id" foreign="id"/>
</foreign-key>
<column name="payment_type_id" type="integer" required="true" phpName="CurrentPaymentTypeId"/>
<foreign-key foreignTable="payment_type" phpName="CurrentPaymentType" refPhpName="CurrentPaymentTypePlace">
<reference local="payment_type_id" foreign="id"/>
</foreign-key>
<column name="delivery_time_type_id" type="integer" required="true" phpName="CurrentDeliveryTimeTypeId"/>
<foreign-key foreignTable="delivery_time_type" phpName="CurrentDeliveryTimeType" refPhpName="CurrentDeliveryTimeTypePlace">
<reference local="delivery_time_type_id" foreign="id"/>
</foreign-key>
<column name="average_cheque" type="integer" required="false" phpName="AvarageCheque"/>
<behavior name="timestampable" />
<behavior name="query_cache" />
<behavior name="archivable" />
</table>
<table name="product_category" phpName="ProductCategory" identifierQuoting="true">
<column name="id" type="integer" required="true" primaryKey="true" autoIncrement="true"/>
<column name="name" type="varchar" size="20" phpName="Name"/>
<column name="alt_name" type="varchar" phpName="AltName"/>
<column name="description" type="varchar" size="300" phpName="Description"/>
<column name="place_id" type="integer" primaryKey="true" phpName="CurrentPlaceId"/>
<foreign-key foreignTable="place" onDelete="CASCADE" phpName="CurrentPlace" refPhpName="CurrentPlaceProductCategory">
<reference local="place_id" foreign="id"/>
</foreign-key>
<behavior name="sortable" />
</table>
<table name="product_product_category" phpName="ProductCategoryProduct" isCrossRef="true">
<column name="product_category_id" type="integer" primaryKey="true"/>
<foreign-key foreignTable="product_category" phpName="CurrentProductCategoryProductCategoryProduct" refPhpName="CurrentProductCategoryProductCategoryProduct" onDelete="CASCADE">
<reference local="product_category_id" foreign="id"/>
</foreign-key>
<column name="product_id" type="integer" primaryKey="true"/>
<foreign-key foreignTable="product" phpName="CurrentProductProductCategoryProduct" refPhpName="CurrentProductProductCategoryProduct" onDelete="CASCADE">
<reference local="product_id" foreign="id"/>
</foreign-key>
</table>`
请帮助我,我已经将place_id
的外键添加到了product_product_category
,但仍然会出现错误
答案 0 :(得分:0)
哦,我发现了我的错误,
我在product_category
上错误地写了primaryKey="true"
到表<column name="place_id" type="integer" primaryKey="true" phpName="CurrentPlaceId"/>
上。只需删除它