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 ...
随机推荐
- drf分页功能
什么是restful规范 是一套规则,用于程序之间进行数据交换的约定. 他规定了一些协议,对我们感受最直接的的是,以前写增删改查需要写4个接口,restful规范的就是1 个接口,根据method的不 ...
- shell脚本中的各种表达式介绍和使用
#前言:在shell脚本中,有各种的表达式,包括有条件测试表达式,文件表达式,字符串表达式,整数表达式,接下来我们来了解一下他们的使用方法 1.条件测试表达式 #首先来看一下条件测试语法 #条件测试语 ...
- 大数据软件安装之HBase(NoSQL数据库)
一.安装部署 1.Zookeeper正常部署 (见前篇博文大数据软件安装之ZooKeeper监控 ) [test@hadoop102 zookeeper-3.4.10]$ bin/zkServer.s ...
- JDK环境的配置,及运用
JAVA为什么可以跨平台 1.JDK配置环境变量 步骤:打开控制面板中系统和安全------系统-----找到高级系统设置点击属性------高级----环境变量------系统变量(JAVA_HOM ...
- Postman从入门到入门
1.Postman简介 Postman是一个接口测试工具,在做接口测试的时候, Postman相当于一个客户端,可以发送请求到服务器端.Postman分为Chrome插件版本(不再更新维护)和Nati ...
- RMQ Tarjan的Sparse-Table算法
参考博客:https://www.cnblogs.com/wenzhixin/p/9714760.html 预处理时间复杂度是O(nlogn),代码如下: void init(const vector ...
- 【多校】2019 Multi-University Training Contest 1官方题解
Blank 定义dp[i][j][k][t]dp[i][j][k][t]dp[i][j][k][t]代表填完前ttt个位置后,{0,1,2,3}\{0,1,2,3\}{0,1,2,3}这4个数字最后一 ...
- Linux基础篇学习——文件目录常用管理命令mkdir,cat,more,less,ln,file,cp,find,split,mv
mkdir 创建目录 -p 递归创建目录 -v 显示创建信息 [root@zycentos7 ~]# mkdir -p {mylinux/{bin,conf,lib,logs,webapps/{doc ...
- 性能测试工具Jmeter你所不知道的内幕
谈到性能测试,大家一定会联想到Jmeter和LoadRunner,这两款工具目前在国内使用的相当广泛,主要原因是Jmeter是开源免费,LoadRunner 11在现网中存在破解版本.商用型性能测试工 ...
- 在dev分支上修改了文件,但是并没有执行git add. 和git commit命令,然后切换到master分支,仍然能看到dev分支的改动现象
当我们创建一个新的分支dev,并且在新分支上修改了原文件,在我们没有提交到仓库的前提下,将分支再切换到master分支上,执行git status ,可以看到dev操作的状态: (1)因为未add的内 ...