【发布时间】:2018-02-21 14:48:11
【问题描述】:
我尝试做的是在一个文件中有两个类用户,在另一个文件中有视频。我的任务是做用户必须登录的数据库,然后他可以上传视频。视频有实体 $uploaded_by 并且应该有来自 User 类的 $id 。
用户.php:
<?php
// src/User.php
namespace Db;
use Doctrine\ORM\Mapping as ORM;
use Doctrine\Common\Collections\ArrayCollection;
/**
* @ORM\Entity @ORM\Table(name="user")
**/
class User
{
/**@ORM\Id @ORM\Column(type="integer") **/
protected $id;
/** @ORM\Column(type="string") **/
protected $name;
/** @ORM\Column(type="datetime") **/
protected $created_at;
/** @ORM\Column(type="datetime", nullable=true) **/
protected $last_login;
视频.php:
<?php
// src/Video.php
namespace Db;
use Doctrine\ORM\Mapping as ORM;
use Doctrine\Common\Collections\ArrayCollection;
/**
* @ORM\Entity @ORM\Table(name="video")
**/
class Video
{
/** @ORM\Id @ORM\Column(type="integer") @ORM\GeneratedValue **/
protected $id;
/** @ORM\Column(type="string") **/
protected $name;
/** @ORM\Column(type="datetime") **/
protected $created_at;
/**
* @OneToOne(targetEntity="User")
* @JoinColumn(name="user_id", referencedColumnName="id")
* @ORM\Column(type="integer") **/
protected $uploaded_by;
/** @ORM\Column(type="integer", nullable=true) **/
protected $deleted;
当我尝试使用
更新 Doctrine 中的 ORM 架构时$ vendor/bin/doctrine orm:schema-tool:update --force --dump-sql
结果是:
In MappingException.php line 52:
No identifier/primary key specified for Entity "Db\User". Every Entity
must
have an identifier/primary key.
- 我做错了什么?
- 如果我的课程连接有问题,我该如何解决?
【问题讨论】: