Alex.Barylski
Alex.Barylski

Reputation: 2933

Generating table schema from entities

I am using Skipper ORM to design/generate entities - everything exports fine - then I do:

app/console doctrine:database:drop --force
app/console doctrine:database:create
app/console doctrine:schema:update --force
app/console doctrine:generate:entities --no-backup MyNamespace/MyBundle

I am receiving an error/exception:

[Doctrine\DBAL\Schema\SchemaException]
There is no column with name 'alternateId' on table 'inventory'.

What gives? The entity in question certainly does have the field:

<?php
namespace Company\DistributionBundle\Entity;
use Doctrine\ORM\Mapping AS ORM;

/**
 * @ORM\Entity(repositoryClass="Company\DistributionBundle\Repository\InventoryRepository")
 * @ORM\Table(
 *     name="inventory",
 *     indexes={@ORM\Index(name="ALTID", columns={"alternateId"})},
 *     uniqueConstraints={
 *         @ORM\UniqueConstraint(name="PKID", columns={"id"}),
 *         @ORM\UniqueConstraint(name="FINDID", columns={"partNumber","partDescription"})
 *     }
 * )
 */
class Inventory
{
    /**
     * @ORM\Id
     * @ORM\Column(type="integer")
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    private $id;

    /**
     * @ORM\Column(type="integer", nullable=false)
     */
    private $alternateId;

    /**
     * @ORM\Column(type="integer", nullable=false)
     */
    private $unitOftMeasure;

    /**
     * @ORM\Column(type="integer", nullable=false)
     */
    private $minimumQuantity;

    /**
     * @ORM\Column(type="integer", nullable=false)
     */
    private $maximumQuantity;

    /**
     * @ORM\Column(type="decimal", nullable=false)
     */
    private $maximumCycles;

    /**
     * @ORM\Column(type="decimal", nullable=false, precision=10, scale=4)
     */
    private $maximumTime;

    /**
     * @ORM\Column(type="decimal", nullable=false, precision=10, scale=2)
     */
    private $listPrice;

    /**
     * @ORM\Column(type="date", nullable=false)
     */
    private $datePrice;

    /**
     * @ORM\Column(type="string", length=50, nullable=false)
     */
    private $partNumber;

    /**
     * @ORM\Column(type="string", length=50, nullable=false)
     */
    private $partDescription;

    /**
     * @ORM\Column(type="text", length=255, nullable=true)
     */
    private $partNotes;

    /**
     * @ORM\OneToOne(targetEntity="Company\DistributionBundle\Entity\Application", inversedBy="inventory")
     * @ORM\JoinColumn(name="application_id", referencedColumnName="id", nullable=false, unique=true)
     */
    private $application;

    /**
     * @ORM\OneToOne(targetEntity="Company\DistributionBundle\Entity\Category", inversedBy="inventory")
     * @ORM\JoinColumn(name="category_id", referencedColumnName="id", nullable=false, unique=true)
     */
    private $category;

    /**
     * @ORM\OneToOne(targetEntity="Company\DistributionBundle\Entity\Manufacturer", inversedBy="inventory")
     * @ORM\JoinColumn(name="manufacturer_id", referencedColumnName="id", nullable=false, unique=true)
     */
    private $manufacturer;

    /**
     * @ORM\ManyToMany(targetEntity="Company\DistributionBundle\Entity\InventoryOptions", mappedBy="inventory")
     */
    private $inventoryOptions;
}

Upvotes: 3

Views: 1256

Answers (1)

amitchhajer
amitchhajer

Reputation: 12830

Try using the doctrine migrations bundle for two reasons:

  1. It helps you manage your production database and all the versions of it. You can check any version any time
  2. It Beautifully creates 'sql migrations' for you. Which you can use to (run migrations) to make changes in database.

Also, it understand your entities, read the annotations and creates the required files.

Go ahead and explore it.

Upvotes: 2

Related Questions