We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 24714
    • 19 Posts
    did everything accroding the tutorial on Using Custom Database Tables in your 3rd Party Components
    built model - everythin’s fine

    problem is in the following line "Note the first time you run this, it might throw an error. This is because xPDO is dynamically creating your database table from your schema. After running, it should show "Total: 0"."

    But actually it doesn’t... error log says the same

    [2011-05-10 22:26:14] (ERROR @ /index.php) Error 42S02 executing statement:
    Array
    (
    [0] => 42S02
    [1] => 1146
    [2] => Table ’revotest.modx_sfinder_stores’ doesn’t exist
    )

    I don’t really want to make all the tables manually? what’s the issue?
      • 22303 MODX Staff
      • 10,725 Posts
      I assume you are using a Release Candidate of MODX 2.1?

      A new option was added to xPDO which requires you to explicitly set this feature on. Auto-table creation is not always desirable—in MODX, we always explicitly create the tables in the setup process, for new installs and upgrades. Similar would be recommended in any packages you create for MODX.

      But you can simply get a new xPDO instance using this option:
      <?php
      $xpdo = new xPDO($dsn, $user, $pass, array(xPDO::OPT_AUTO_CREATE_TABLES => true));


      NOTE: In MODX 2.1, you can manually set options in the config file in the new variable $config_options; these values will be preserved on upgrades.

      Or you can use setOption() to change it for the remainder of the current request, at anytime:
      <?php
      $modx->setOption(xPDO::OPT_AUTO_CREATE_TABLES, true);


      Documentation updates are in progress on all of these changes in xPDO 2.1.x and MODX 2.1.x.
        • 24714
        • 19 Posts
        omfg - I love u!!! =)
          • 24881
          • 4 Posts
          Excuse my ignorance, but where do I put this code? I have the same problem. I’m not familiar with Xpdo and don’t know where to start. huh
            • 24068
            • 4 Posts
            It depends on the code, but always somewhere before you use the table.

            Illustration:

            $modx->setOption(xPDO::OPT_AUTO_CREATE_TABLES, true);
            $item = $modx->getObject('mySomething', 1);
            


            Maybe one call to $modx->setOption(xPDO::OPT_AUTO_CREATE_TABLES, true); in a file that is included by all your other files, a config.php or something like that.
              • 22303 MODX Staff
              • 10,725 Posts
              You can set this setting on, but it is better to create the tables with xPDOManager::createObjectContainer() as part of a package. Typically, this would be done by a resolver on one of the main vehicles in the transport package.

              <?php
              $modx->getManager();
              $modx->manager->createObjectContainer('myClassName');
              
                • 24881
                • 4 Posts
                Where do I find the xpdo manager? That is where I am lost I think.
                  • 22303 MODX Staff
                  • 10,725 Posts
                  Quote from: retrobou at May 31, 2011, 05:14 PM

                  Where do I find the xpdo manager? That is where I am lost I think.
                  If you are not developing an Extra for MODX, you really shouldn’t need to know where to put this code. It is the responsibility of the people creating and sharing the Extra in the repository.

                  If the issue is you are using an Extra that is not explicitly creating the tables it needs, you should push back on the maintainer of the Extra to address this, but you can work around it by editing your config.inc.php (in MODX 2.1+ ONLY). There is a variable there now called $config_options which appears right below the $database_dsn and which you can manually edit. Values you place here will be preserved on future upgrades —
                  $config_options = array (
                      xPDO::OPT_AUTO_CREATE_TABLES => true
                  );
                    • 24881
                    • 4 Posts
                    Thanks for that, I am not developing an extra but installing vision cart. Other threads suggest that tables are not being created. I will try your fix, I believe the vision cart developer is aware of this based on the other threads.
                    Thanks!
                      • 18373 ☆ A M B ☆
                      • 3,141 Posts
                      The guys from Digital Butter suggested an easier fix, namely adding a system setting with the key ’auto_create_tables’ and giving it the value 1, that would also fix it.

                      For VisionCart specifically here’s a little code (that I sent you on Twitter, but also for others to use) to create its tables: https://gist.github.com/1001424 I filed it in their bug tracker as well so I assume they’re fixing that in the next release.........
                        Mark Hamstra • Developer spending his days working on Premium Extras and a MODX Site Dashboard with the ability to remotely upgrade MODX and extras to make the MODX world a little better.

                        Tweet me @mark_hamstra, check my infrequent blog at markhamstra.com, my slightly more frequent ramblings at MODX.today or see code at Github.