title: Symfony 1.4 Doctrine MySQL Database table Views Module
body: <p>With symfony 1.4 and doctrine you can generate frontend pages / modules with this command in your project directory: <strong>php symfony doctrine:generate-module --with-show --non-verbose-templates frontend tablename tableclassname</strong></p>
  
  <p>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: <strong>Cannot generate a module for a model without a primary key.</strong> The view inherits the primary key from the table it's reading off of, is my understanding. </p>
  
  <p>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>
  
  <p>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 &amp; I still get the same error when trying to generate the frontend module in symfony. </p>
  
  <pre><code>tableName: v_tablename
   columns:
    id:
    type: integer(4)
    fixed: false
    unsigned: false
    primary: true --&gt; This used to be primary: false
    default: '0'
    notnull: true
    autoincrement: false
  </code></pre>
  
  <p>*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:</p>
  
  <p>1 - <strong>php symfony doctrine:build-schema</strong> (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.</p>
  
  <p>2 - <strong>php symfony doctrine:build-model</strong> Once you do step 2 after adding your primary keys, you can then successfully generate your module</p>
  
  <p>3 - <strong>php symfony doctrine:generate-module frontend module model</strong></p>