Symfony 1.4 Doctrine MySQL 数据库表视图模块

发布于 2024-11-08 07:14:01 字数 1270 浏览 0 评论 0原文

使用symfony 1.4和doctrine,您可以在项目目录中使用以下命令生成前端页面/模块: php symfonydoctrine:generate-module --with-show --non-verbose-templates frontend tablename tableclassname

这对于实际表效果很好,但是当我尝试在 MySQL 数据库视图而不是 MySQL 数据库表上运行此命令时,我收到此错误:无法为没有主键的模型生成模块。 的我的理解是,视图继承了它正在读取的表的主键。

有谁知道解决这个问题的方法,使用 symfony 仍然很容易维护吗?如果我可以将数据库视图与 symfony 框架一起使用,那就太棒了。如果您需要更多详细信息,请告诉我。一般来说,无论多么复杂或简单,任何视图似乎都不起作用。

PS 我尝试编辑 ./config/doctrine/schema.yml 文件以将视图中的 id 列更改为主键,它位于实际的表中当尝试在 symfony 中生成前端模块时,我仍然遇到相同的错误。

tableName: v_tablename
 columns:
  id:
  type: integer(4)
  fixed: false
  unsigned: false
  primary: true --> This used to be primary: false
  default: '0'
  notnull: true
  autoincrement: false

*KI 弄清楚了,但由于我是新用户,所以要到 8 小时后才能发布我的答案。 当我编辑 schema.yml 文件时,我就在 1/2 处。如果您尝试从视图生成模块,并且您已经在 symfony 之外构建了数据库模型,例如使用 MySQL Workbench,按照原则,您必须构建模式,然后从现有数据库结构在 symfony 中构建模型,如下所示:

1 - php symfonydoctrine:build-schema (这会生成 schema.yml 文件等)但是,如果您的数据库架构中有视图,则不会在 schema.yml 中生成主键文件。手动编辑它并根据需要将primary:false更改为primary:true。

2 - php symfony 学说:build-model 添加主键后执行步骤 2,您就可以成功生成模块

3 - php symfony 学说:generate-module 前端模块模型< /强>

With symfony 1.4 and doctrine you can generate frontend pages / modules with this command in your project directory: php symfony doctrine:generate-module --with-show --non-verbose-templates frontend tablename tableclassname

This works great with actual tables, however when I try to run this command on top of a MySQL DB View instead of a MySQL DB Table, I get this error: Cannot generate a module for a model without a primary key. The view inherits the primary key from the table it's reading off of, is my understanding.

Does anyone know a work around for this, that is still pretty easy to maintain with symfony? It would be amazing if I could use DB Views with the symfony framework. Let me know if you need any more details. In general no view seems to work no matter how complex or simple.

P.S. I tried editing the ./config/doctrine/schema.yml file to change the id column in the view to the primary key, which it is in the actual table & I still get the same error when trying to generate the frontend module in symfony.

tableName: v_tablename
 columns:
  id:
  type: integer(4)
  fixed: false
  unsigned: false
  primary: true --> This used to be primary: false
  default: '0'
  notnull: true
  autoincrement: false

*K I figured it out, but I can't post my answer until after 8 hours since I am a new user.
I was 1/2 way there when I edited the schema.yml file. If you are trying to generate a module off a view, and you have built your DB Model outside of symfony, say using MySQL Workbench, with doctrine you have to build your schema then build your model in symfony from your existing Database Structure like this:

1 - php symfony doctrine:build-schema (This generates the schema.yml file, etc.) However if you have views in your Database Schema, the primary keys aren't generated in the schema.yml file. Edit it manually and change the primary:false to primary:true accordingly where you need them.

2 - php symfony doctrine:build-model Once you do step 2 after adding your primary keys, you can then successfully generate your module

3 - php symfony doctrine:generate-module frontend module model

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

聚集的泪 2024-11-15 07:14:01

小修正...这会起作用,但是我错过了 2 和 2 之间的一步。 3 影响表单页面并分解步骤 1。

1 - php symfony 主义:build-schema (这会生成 schema.yml 文件等)

2 - 编辑 ./config/学说/schema.yml 文件。对于您的视图定义,请根据需要将primary:false 更改为primary:true。我还注意到,在 MySQL 中,自从 boolean = tinyint(1) 以来,schema.yml 检测到整数(1) 而不是布尔值。您还可以根据需要将整数(1)数据类型更改为布尔值。

tableName: v_tablename
   columns:
     id:
     type: integer(4)
     fixed: false
     unsigned: false
     primary: false --> change to, primary: true
     default: '0'
     notnull: true
     autoincrement: false

tableName: tablename
   columns:

     active:
     type: integer(1) --> change to, type: boolean
     fixed: false
     unsigned: false
     primary: false
     default: '0'
     notnull: true
     autoincrement: false

3 - php symfony 学说:build-model

4 - php symfony 学说:build-forms

5 - php symfony 学说:generate-module 前端模块

Minor correction... this will work, however I missed a step in between 2 & 3 that effects the form pages and broke down step 1.

1 - php symfony doctrine:build-schema (This generates the schema.yml file, etc.)

2 - Edit ./config/doctrine/schema.yml file. For your view definitions, change the primary:false to primary:true accordingly where you need them. I also noticed that in MySQL since boolean = tinyint(1), the schema.yml detects integer(1) and not boolean. You can also change your integer(1) datatypes to boolean where you need too.

tableName: v_tablename
   columns:
     id:
     type: integer(4)
     fixed: false
     unsigned: false
     primary: false --> change to, primary: true
     default: '0'
     notnull: true
     autoincrement: false

tableName: tablename
   columns:

     active:
     type: integer(1) --> change to, type: boolean
     fixed: false
     unsigned: false
     primary: false
     default: '0'
     notnull: true
     autoincrement: false

3 - php symfony doctrine:build-model

4 - php symfony doctrine:build-forms

5 - php symfony doctrine:generate-module frontend module

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文