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 ...
随机推荐
- vs2017打包exe安装包
1,安装扩展程序Install Projects 2,在打开的界面搜索Install,找到Install Projects 3,在要打包的项目解决方案下创建一个生成exe的项目 4,在打包项目的文件系 ...
- linux 执行计划任务crontab
crontab 一些常用的命令 service crond start //启动服务 service crond stop //关闭服务 service crond restart //重启服务 se ...
- SQL常见错误总结
目录 语法错误 标点错漏 重命名 数据拼接 null值 逻辑顺序 函数错误 参数的数量 参数的格式 逻辑错误 数据重复 无效筛选 标签重叠 时间错位 SQL是数据分析中最高频的操作之一,本文梳理常见的 ...
- vue前端登录
登陆流程 1.用户登录从后台获取 token,菜单数据 2.将token和菜单数据存入sessionStorage,token用来校验用户是否已经登录 2.将返回的菜单数据前端生成对应菜单列表 3.处 ...
- Journal of Proteome Research | Quantitative Subcellular Proteomics of the Orbitofrontal Cortex of Schizophrenia Patients (精神分裂症病人眶额叶皮层亚细胞结构的定量蛋白质组学研究)(解读人:王聚)
期刊名:Journal of Proteome Research 发表时间:(2019年10月) IF:3.78 单位: 里约热内卢联邦大学 坎皮纳斯州立大学 坎皮纳斯州立大学神经生物学中心 卡拉博大 ...
- python https请求报错:SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED]
python爬虫,使用requests库发送https请求报错:SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] 解决方法: imp ...
- 性能测试从零开始-LoadRunner入门
写在前面 又到了公司每月的读书会,经过上个月的试运行后,公司把读书会纳入每月的绩效考核中,听到这个消息,当时我的内心是崩溃的,不过从另一方面来讲,对于我来说也一件好事儿,这样可以督促自己养成读书的习惯 ...
- 通过源码理解Spring中@Scheduled的实现原理并且实现调度任务动态装载
前提 最近的新项目和数据同步相关,有定时调度的需求.之前一直有使用过Quartz.XXL-Job.Easy Scheduler等调度框架,后来越发觉得这些框架太重量级了,于是想到了Spring内置的S ...
- OpenCV-Python 如何使用背景分离方法 | 四十六
目标 背景分离(BS)是一种通过使用静态相机来生成前景掩码(即包含属于场景中的移动对象像素的二进制图像)的常用技术. 顾名思义,BS计算前景掩码,在当前帧与背景模型之间执行减法运算,其中包含场景的静态 ...
- 食物图片变菜谱:这篇CVPR论文让人人都可以学习新料理
根据 Facebook 的统计,Instgram 上的美食图片数量已经超过 3 亿张.然而,获取食物烹饪方法的途径依然有限,例如,通过烹饪网站或相关教程.怎样能够挖掘丰富食物图片背后的烹饪方法,让每个 ...