How to generate entities from database schema using doctrine-orm-module
1、安装好doctrine,在composer.json中添加如下
"require": {
"php": "^5.6 || ^7.0",
"doctrine/doctrine-orm-module": "*",
},
执行composer install
2、在yourAPP/config/modules.config.php添加doctrine module
return [
'Zend\ServiceManager\Di',
'Zend\Session',
'Zend\Mvc\Plugin\Prg',
'Zend\Mvc\Plugin\Identity',
'Zend\Mvc\Plugin\FlashMessenger',
'Zend\Mvc\Plugin\FilePrg',
'Zend\Mvc\I18n',
'Zend\Mvc\Console',
'Zend\Log',
'Zend\Form',
'Zend\Db',
'Zend\Cache',
'Zend\Router',
'Zend\Validator',
'ZendDeveloperTools',
'Application',
'DoctrineModule',
'DoctrineORMModule',
];
3、在yourAPP/config/autoload/local.php添加如下
<?php
/**
* Local Configuration Override
*
* This configuration override file is for overriding environment-specific and
* security-sensitive configuration information. Copy this file without the
* .dist extension at the end and populate values as needed.
*
* @NOTE: This file is ignored from Git by default with the .gitignore included
* in ZendSkeletonApplication. This is a good practice, as it prevents sensitive
* credentials from accidentally being committed into version control.
*/
use Doctrine\DBAL\Driver\PDOMySql\Driver as PDOMySqlDriver;
return [
'doctrine' => [
'connection' => [
'orm_default' => [
'driverClass' => PDOMySqlDriver::class,
'params' => [
'host' => '10.11.1.2',
'port' => '',
'user' => 'xxx',
'password' => 'xxx',
'dbname' => 'user_shanmaohuwai',
]
],
],
],
];
4、使用doctrine命令生成entity(https://www.e-learn.cn/content/wangluowenzhang/609311)
问题:
I am using "doctrine/doctrine-orm-module": "0.7.0" with ZF2.
Once I create Entities I usually run following commands to sync and generate database automatically according to my entities.
./vendor/bin/doctrine-module orm:validate-schema
./vendor/bin/doctrine-module orm:schema-tool:create
Is there a way to make this process reverse? I mean, Can I generate entities from existing database in mysql?
回答1:
We use a batch script:
@ECHO OFF mkdir EXPORT
call .\vendor\bin\doctrine-module orm:convert-mapping --force --from-database annotation ./EXPORT/
call .\vendor\bin\doctrine-module orm:generate-entities ./EXPORT/ --generate-annotations=true pause
orm:convert-mapping and orm:generate-entities is probably what you are looking for.
回答2:
There's a nice blog written on this here
Edit: It can be done by using the commands below:
1. convert-mapping (Table & Entity):
./vendor/doctrine/doctrine-module/bin/doctrine-module orm:convert-mapping --namespace="Album\\Entity\\" --force --from-database annotation ./module/Album/src/
2. Generates getter and setter
./vendor/doctrine/doctrine-module/bin/doctrine-module orm:generate-entities ./module/Album/src/ --generate-annotations=true
回答3:
Try just it
doctrine orm:convert-mapping -f --from-database annotation entities/ doctrine orm:generate-entities --generate-annotations="true" entities/
http://wildlyinaccurate.com/useful-doctrine-2-console-commands/
cd appdir
./vendor/doctrine/doctrine-module/bin/doctrine-module orm:convert-mapping --namespace="Application\\Entity\\" --force --from-database annotation ./module/Application/src/
./vendor/doctrine/doctrine-module/bin/doctrine-module orm:generate-entities ./module/Application/src/ --generate-annotations=true
How to generate entities from database schema using doctrine-orm-module的更多相关文章
- database schema
数据中有4个Schema无法被删除 ● dbo, 具有db_owner或者db_ddl_admin 的用户,新创建对象默认schema就是dbo ● guest , 用来给guest 用户使用,这个s ...
- Could not update Activiti database schema: unknown version from database: '5.20.0.1'
转: Could not update Activiti database schema: unknown version from database: '5.20.0.1' 2017年11月22日 ...
- Create schema error (unknown database schema '')
Andrey Devyatka 4 years ago Permalink Raw Message Hi,Please tell me, can I use the static library in ...
- [odb-users] Create schema error (unknown database schema '')
Boris Kolpackov boris at codesynthesis.comFri May 31 11:13:02 EDT 2013 Previous message: [odb-users] ...
- PostgreSQL中,database,schema,table之间关系
从逻辑上看,schema,table,都是位于database之下. 首先,在postgres数据库下建立表(相当于建立在public schema下): [pgsql@localhost bin]$ ...
- 改善database schema
本文地址:http://blog.csdn.net/sushengmiyan/article/details/50422102 本文作者:苏生米沿 Hibernate 读取你java模型类的映射元数据 ...
- openfire 安装配置时出现The Openfire database schema does not appear to be installed. Follow the installati错误的解决方案
最近再弄openfire用openLDAP整合,本来没整合的时候选的标准数据库没问题,但是现在用嵌入式数据库,就报错了,,, 报错原因:没有导入openfire的数据表 解放办法: 1.登陆数据库 , ...
- Could not update Activiti database schema: unknown version from database: '5.22.x.x'
原因:activiti 相关的jar版本和表 act_ge_property 中 schema.version 所存储的版本不一致导致报错的. 查看activiti 相关jar版本 然后修改表中的版本 ...
- Database Schema Reader
数据架构与INSERT脚本生成 https://dbschemareader.codeplex.com/wikipage?title=Writing%20Data&referringTitle ...
随机推荐
- js 实现弹性运动的简单应用----导航栏中弹性
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- Hadoop集群搭建(二)~centos6.8的安装
这篇记录在创建好的虚拟机中安装centos6.8 1,在虚拟机界面-选择编辑虚拟机设置 2,CD/DVD,选择使用ISO映像文件,找到安装包的位置,确定 3,回到虚拟机的界面,开启此虚拟机 4,安装 ...
- js 验证输入框是否为空
很多时候,菜鸟在对输入框是否输入值进行验证时,总会把输入“空字符串”这一状况给忽略掉.嗯,我就这样,所以记下,以后回忆下还是不错滴 <input type="text" id ...
- python基于scrapy框架的反爬虫机制破解之User-Agent伪装
user agent是指用户代理,简称 UA. 作用:使服务器能够识别客户使用的操作系统及版本.CPU 类型.浏览器及版本.浏览器渲染引擎.浏览器语言.浏览器插件等. 网站常常通过判断 UA 来给不同 ...
- 推荐几个来自 MOOCs的 Data Science
数据科学是一个大领域,如果你想成为一个优秀的数据专家,自学是必要的技能. MOOCs是数据科学的主要来源.有许多网站提供了 MOOCs,比如Coursera.Coursera和Udacity都还不错. ...
- Cobaltstrike指令大全/beacon命令
BeaconCommands=============== Command Description ------- ----------- browserpivot 注入受害者浏览器进程 bypass ...
- JMM内存模型、CPU缓存一致性原则(MESI)、指令重排、as-if-serial、happen-before原则
JMM三大特性原子性 汇编指令 --原子比较和交换在底层的支持 cmp-chxg 总线加锁机制 Synchronized Lock锁机制 public class VolatileAtomicSamp ...
- 题解 P1002 【过河卒】
正文 简单描述一下题意: 士兵想要过河,他每一次可以往下走一格,也可以往右走一格,但马一步走到的地方是不能走的,问走到\(n\)行,\(m\)列有多少种走法 我们显然应该先根据马的位置将不能走的格子做 ...
- 谷歌出品EfficientNet:比现有卷积网络小84倍,比GPipe快6.1倍
[导读]谷歌AI研究部门华人科学家再发论文<EfficientNet:重新思考CNN模型缩放>,模型缩放的传统做法是任意增加CNN的深度和宽度,或使用更大的输入图像分辨率进行训练,而使用E ...
- 《Flutter 动画系列一》25种动画组件超全总结
动画运行的原理 任何程序的动画原理都是一样的,即:视觉暂留,视觉暂留又叫视觉暂停,人眼在观察景物时,光信号传入大脑神经,需经过一段短暂的时间,光的作用结束后,视觉形象并不立即消失,这种残留的视觉称&q ...