首页 \ 问答 \ 为magento添加数据库表时出现异常(Exception while adding database tables for magento)

为magento添加数据库表时出现异常(Exception while adding database tables for magento)

我正在使用WAMP服务器在magento 1.6.2.0上创建我的模块; 当我尝试将我的表添加到magento数据库时,这是一个异常,并且在Mysql页面中我的表没有创建,但我在“core_ressource”表下找到了我的模块的名称; 你能帮我吗 ?

这是我的PHP升级页面:

<?php


    $installer = $this;

    $installer->startSetup();
    /**
     * Create table 'interactivebanner/interactivebanner'
     */
    $table = $installer->getConnection()
        ->newTable($installer->getTable('interactivebanner/interactivebanner'))
        ->addColumn('entity_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array(
            'identity'  => true,
            'unsigned'  => true,
            'nullable'  => false,
            'primary'   => true,
            ), 'Entity Id')
        ->addColumn('name', Varien_Db_Ddl_Table::TYPE_TEXT,100, array(
            'nullable'  => false,
            'default'   => '',
            ), 'Name')
        ->addColumn('link', Varien_Db_Ddl_Table::TYPE_TEXT,255, array(
            'nullable'  => false,
            'default'   => '',
            ), 'Link')
        ->addColumn('status', Varien_Db_Ddl_Table::TYPE_INTEGER,null, array(
            'unsigned'  => true,
            'nullable'  => false,
            'default'   => '0',
            ), 'Status');
    $installer->getConnection()->createTable($table);

     /**
     * Create table 'interactivebanner/interactivebannerprod'
     */
    $table = $installer->getConnection()
        ->newTable($installer->getTable('interactivebanner/interactivebannerprod'))
        ->addColumn('value_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array(
            'identity'  => true,
            'nullable'  => false,
            'primary'   => true,
            ), 'Value ID')
        ->addColumn('tag_content', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array(
            'nullable'  => false,
            'default'   => '',
            ), 'Status id')
        ->addColumn('entity_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array(
            'unsigned'  => true,
            'nullable'  => false,
            'default'   => '0',
             ), 'Entity Id')
        ->addColumn('position_v', Varien_Db_Ddl_Table::TYPE_TEXT,10, array(
            'nullable'  => false,
            'default'   => '0',
            ), 'Position V')
        ->addColumn('position_h', Varien_Db_Ddl_Table::TYPE_TEXT,10, array(
            'nullable'  => false,
            'default'   => '0',
            ), 'Position H')
        ->addForeignKey($installer->getFkName('interactivebanner/interactivebanner', 'entity_id', 'interactivebanner/interactivebannerprod', 'entity_id'),
            'entity_id', $installer->getTable('interactivebanner/interactivebannerprod'), 'entity_id', Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE);
    $installer->getConnection()->createTable($table);

  $installer->endSetup();

这是例外:

Exception Object
(
    [message:protected] => Notice: Trying to get property of non-object  in C:\wamp\www\ce_1.6.2.0\app\code\core\Mage\Core\Model\Resource.php on line 230
    [string:Exception:private] => 
    [code:protected] => 0
    [file:protected] => C:\wamp\www\ce_1.6.2.0\app\code\core\Mage\Core\functions.php
    [line:protected] => 245
    [trace:Exception:private] => Array
        (
            [0] => Array
                (
                    [file] => C:\wamp\www\ce_1.6.2.0\app\code\core\Mage\Core\Model\Resource.php
                    [line] => 230
                    [function] => mageCoreErrorHandler
                    [args] => Array
                        (
                            [0] => 8
                            [1] => Trying to get property of non-object
                            [2] => C:\wamp\www\ce_1.6.2.0\app\code\core\Mage\Core\Model\Resource.php
                            [3] => 230
                            [4] => Array
                                (
                                    [model] => Kiwi_InteractiveBanner_Resource
                                    [entity] => interactivebanner
                                    [modelsNode] => Mage_Core_Model_Config_Element Object
                                        (
                                            [varien] => Mage_Core_Model_Config_Element Object
                                                (
                                                    [class] => Varien
                                                )

                                            [core] => Mage_Core_Model_Config_Element Object
                                                (
                                                    [class] => Mage_Core_Model
                                                    [resourceModel] => core_resource
                                                )

                                            [core_resource] => Mage_Core_Model_Config_Element Object
                                                (
                                                    [class] => Mage_Core_Model_Resource
                                                    [deprecatedNode] => core_mysql4
                                                    [entities] => Mage_Core_Model_Config_Element Object
                                                        (
                                                            [config_data] => Mage_Core_Model_Config_Element Object
                                                                (
                                                                    [table] => core_config_data
                                                                )

                                                            [website] => Mage_Core_Model_Config_Element Object
                                                                (
                                                                    [table] => core_website
                                                                )

                                                            [store] => Mage_Core_Model_Config_Element Object
                                                                (
                                                                    [table] => core_store
                                                                )

                                                            [resource] => Mage_Core_Model_Config_Element Object
                                                                (
                                                                    [table] => core_resource
                                                                )

                                                            [cache] => Mage_Core_Model_Config_Element Object
                                                                (
                                                                    [table] => core_cache
                                                                )

                                                            [cache_tag] => Mage_Core_Model_Config_Element Object
                                                                (
                                                                    [table] => core_cache_tag
                                                                )

                                                            [cache_option] => Mage_Core_Model_Config_Element Object
                                                                (
                                                                    [table] => core_cache_option
                                                                )

                                                            [store_group] => Mage_Core_Model_Config_Element Object
                                                                (
                                                                    [table] => core_store_group
                                                                )

                                                            [config_field] => Mage_Core_Model_Config_Element Object
                                                                (
                                                                    [table] => core_config_field
                                                                )

                                                            [email_template] => Mage_Core_Model_Config_Element Object
                                                                (
                                                                    [table] => core_email_template
                                                                )

                                                            [variable] => Mage_Core_Model_Config_Element Object
                                                                (
                                                                    [table] => core_variable
                                                                )

                                                            [variable_value] => Mage_Core_Model_Config_Element Object
                                                                (
                                                                    [table] => core_variable_value
                                                                )

                                                            [translate] => Mage_Core_Model_Config_Element Object
                                                                (
                                                                    [table] => core_translate
                                                                )

                                                            [session] => Mage_Core_Model_Config_Element Object
                                                                (
                                                                    [table] => core_session
                                                                )

                                                            [layout_update] => Mage_Core_Model_Config_Element Object
                                                                (
                                                                    [table] => core_layout_update
                                                                )

                                                            [layout_link] => Mage_Core_Model_Config_Element Object
                                                                (
                                                                    [table] => core_layout_link
                                                                )

                                                            [url_rewrite] => Mage_Core_Model_Config_Element Object
                                                                (
                                                                    [table] =>  ...

这是我的config.xml的一部分

    <models>
        <interactivebanner>
            <class>Kiwi_InteractiveBanner_Model</class>
            <resourceModel>Kiwi_InteractiveBanner_Resource</resourceModel>
        </interactivebanner>
        <interactivebanner_resource>
            <class>Kiwi_InteractiveBanner_Model_Resource</class>
            <entities>
                <interactivebanner>
                    <table>interactivebanner</table>
                </interactivebanner>
                <interactivebannerprod>
                    <table>interactivebannerprod</table>
                </interactivebannerprod>
            </entities>
        </interactivebanner_resource>
    </models>

I'm creating my module on magento 1.6.2.0 with WAMP server; when I try to add my tables to the magento database theres an exception, and in the Mysql page my tables a not created but I found the name of my module with under the table "core_ressource" ; can you help me please ?

This is my PHP upgrade page:

<?php


    $installer = $this;

    $installer->startSetup();
    /**
     * Create table 'interactivebanner/interactivebanner'
     */
    $table = $installer->getConnection()
        ->newTable($installer->getTable('interactivebanner/interactivebanner'))
        ->addColumn('entity_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array(
            'identity'  => true,
            'unsigned'  => true,
            'nullable'  => false,
            'primary'   => true,
            ), 'Entity Id')
        ->addColumn('name', Varien_Db_Ddl_Table::TYPE_TEXT,100, array(
            'nullable'  => false,
            'default'   => '',
            ), 'Name')
        ->addColumn('link', Varien_Db_Ddl_Table::TYPE_TEXT,255, array(
            'nullable'  => false,
            'default'   => '',
            ), 'Link')
        ->addColumn('status', Varien_Db_Ddl_Table::TYPE_INTEGER,null, array(
            'unsigned'  => true,
            'nullable'  => false,
            'default'   => '0',
            ), 'Status');
    $installer->getConnection()->createTable($table);

     /**
     * Create table 'interactivebanner/interactivebannerprod'
     */
    $table = $installer->getConnection()
        ->newTable($installer->getTable('interactivebanner/interactivebannerprod'))
        ->addColumn('value_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array(
            'identity'  => true,
            'nullable'  => false,
            'primary'   => true,
            ), 'Value ID')
        ->addColumn('tag_content', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array(
            'nullable'  => false,
            'default'   => '',
            ), 'Status id')
        ->addColumn('entity_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array(
            'unsigned'  => true,
            'nullable'  => false,
            'default'   => '0',
             ), 'Entity Id')
        ->addColumn('position_v', Varien_Db_Ddl_Table::TYPE_TEXT,10, array(
            'nullable'  => false,
            'default'   => '0',
            ), 'Position V')
        ->addColumn('position_h', Varien_Db_Ddl_Table::TYPE_TEXT,10, array(
            'nullable'  => false,
            'default'   => '0',
            ), 'Position H')
        ->addForeignKey($installer->getFkName('interactivebanner/interactivebanner', 'entity_id', 'interactivebanner/interactivebannerprod', 'entity_id'),
            'entity_id', $installer->getTable('interactivebanner/interactivebannerprod'), 'entity_id', Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE);
    $installer->getConnection()->createTable($table);

  $installer->endSetup();

and this is the exception:

Exception Object
(
    [message:protected] => Notice: Trying to get property of non-object  in C:\wamp\www\ce_1.6.2.0\app\code\core\Mage\Core\Model\Resource.php on line 230
    [string:Exception:private] => 
    [code:protected] => 0
    [file:protected] => C:\wamp\www\ce_1.6.2.0\app\code\core\Mage\Core\functions.php
    [line:protected] => 245
    [trace:Exception:private] => Array
        (
            [0] => Array
                (
                    [file] => C:\wamp\www\ce_1.6.2.0\app\code\core\Mage\Core\Model\Resource.php
                    [line] => 230
                    [function] => mageCoreErrorHandler
                    [args] => Array
                        (
                            [0] => 8
                            [1] => Trying to get property of non-object
                            [2] => C:\wamp\www\ce_1.6.2.0\app\code\core\Mage\Core\Model\Resource.php
                            [3] => 230
                            [4] => Array
                                (
                                    [model] => Kiwi_InteractiveBanner_Resource
                                    [entity] => interactivebanner
                                    [modelsNode] => Mage_Core_Model_Config_Element Object
                                        (
                                            [varien] => Mage_Core_Model_Config_Element Object
                                                (
                                                    [class] => Varien
                                                )

                                            [core] => Mage_Core_Model_Config_Element Object
                                                (
                                                    [class] => Mage_Core_Model
                                                    [resourceModel] => core_resource
                                                )

                                            [core_resource] => Mage_Core_Model_Config_Element Object
                                                (
                                                    [class] => Mage_Core_Model_Resource
                                                    [deprecatedNode] => core_mysql4
                                                    [entities] => Mage_Core_Model_Config_Element Object
                                                        (
                                                            [config_data] => Mage_Core_Model_Config_Element Object
                                                                (
                                                                    [table] => core_config_data
                                                                )

                                                            [website] => Mage_Core_Model_Config_Element Object
                                                                (
                                                                    [table] => core_website
                                                                )

                                                            [store] => Mage_Core_Model_Config_Element Object
                                                                (
                                                                    [table] => core_store
                                                                )

                                                            [resource] => Mage_Core_Model_Config_Element Object
                                                                (
                                                                    [table] => core_resource
                                                                )

                                                            [cache] => Mage_Core_Model_Config_Element Object
                                                                (
                                                                    [table] => core_cache
                                                                )

                                                            [cache_tag] => Mage_Core_Model_Config_Element Object
                                                                (
                                                                    [table] => core_cache_tag
                                                                )

                                                            [cache_option] => Mage_Core_Model_Config_Element Object
                                                                (
                                                                    [table] => core_cache_option
                                                                )

                                                            [store_group] => Mage_Core_Model_Config_Element Object
                                                                (
                                                                    [table] => core_store_group
                                                                )

                                                            [config_field] => Mage_Core_Model_Config_Element Object
                                                                (
                                                                    [table] => core_config_field
                                                                )

                                                            [email_template] => Mage_Core_Model_Config_Element Object
                                                                (
                                                                    [table] => core_email_template
                                                                )

                                                            [variable] => Mage_Core_Model_Config_Element Object
                                                                (
                                                                    [table] => core_variable
                                                                )

                                                            [variable_value] => Mage_Core_Model_Config_Element Object
                                                                (
                                                                    [table] => core_variable_value
                                                                )

                                                            [translate] => Mage_Core_Model_Config_Element Object
                                                                (
                                                                    [table] => core_translate
                                                                )

                                                            [session] => Mage_Core_Model_Config_Element Object
                                                                (
                                                                    [table] => core_session
                                                                )

                                                            [layout_update] => Mage_Core_Model_Config_Element Object
                                                                (
                                                                    [table] => core_layout_update
                                                                )

                                                            [layout_link] => Mage_Core_Model_Config_Element Object
                                                                (
                                                                    [table] => core_layout_link
                                                                )

                                                            [url_rewrite] => Mage_Core_Model_Config_Element Object
                                                                (
                                                                    [table] =>  ...

this is a part of my config.xml

    <models>
        <interactivebanner>
            <class>Kiwi_InteractiveBanner_Model</class>
            <resourceModel>Kiwi_InteractiveBanner_Resource</resourceModel>
        </interactivebanner>
        <interactivebanner_resource>
            <class>Kiwi_InteractiveBanner_Model_Resource</class>
            <entities>
                <interactivebanner>
                    <table>interactivebanner</table>
                </interactivebanner>
                <interactivebannerprod>
                    <table>interactivebannerprod</table>
                </interactivebannerprod>
            </entities>
        </interactivebanner_resource>
    </models>

原文:https://stackoverflow.com/questions/10511795
更新时间:2022-03-07 13:03

最满意答案

你应该使用新的,而不是malloc。 当内存不足时抛出新的std :: bad_alloc。 如果分配失败(或者由于其他原因导致初始化有问题),应该从构造函数传播一个异常,因为这是防止析构函数被调用的唯一方法。 如果构造函数成功完成,则必须调用析构函数(当然,除非它是堆分配的并且从不释放)。


You should use new, not malloc. new throws std::bad_alloc when you are out of memory. An exception should be propagated from the constructor if you fail to allocate (or for any other reason have a problem with initialization), as this is the only way you prevent the destructor from being called. If the constructor successfully completes, the destructor must be called (unless, of course, it was heap allocated and never freed).

相关问答

更多
  • 严格地说,回答标题中的问题,答案是它取决于实施。 某些实现可能会分配内存,而其他实现可能不会。 虽然您的代码中存在其他固有问题,我将在下面详细说明。 注意:这最初是我对这个问题所做的一系列评论。 我认为评论过多,并将他们转移到这个答案。 当您检查输出时,您将看到它将按预期打印一些数字,但最后一些是乱码。 我相信使用分段内存模型的系统,分配被“四舍五入”到一定的大小。 即如果你分配X字节,你的程序确实拥有那些X字节,但是,你也能够(错误地)运行超过这些X字节一段时间,然后CPU注意到你违反了边界并发送了一个S ...
  • 假设你想为n数组分配存储空间,每个数组都有n字符串,每个字符串长达MAX_STR ,代码中有一些错误 matrix = calloc(n*MAX_STR, sizeof(char**)); 应该 matrix = calloc(n, sizeof(char**)); 和 for(i = 0; i < MAX_STR; i++) { 应该 for(i = 0; i < n; i++) { 再详细一点, matrix = calloc(n*MAX_STR, sizeof(char**)); for(z ...
  • 除了使我应该采取的本地数据之外还有一个步骤吗? 而已。 它应该如下所示: void proc() { t_thing things[500]; // << you could use std::array here too } 令人怀疑的是,它对您的需求“缓慢”。 如果要改进这一点,指定对齐可能会有所帮助。 Is there a step beyond making the data local that I should take? Nothing more. It should look like ...
  • 你应该参考这里和这里的类似问题。 基本上,如果构造函数抛出异常,那么安全的是,对象本身的内存被再次释放。 虽然在构造函数中已经声明了其他内存,但是在离开构造函数之前,您将自己释放它。 对于您的问题,WHO删除内存,答案是新操作符(由编译器生成)后面的代码。 如果它识别出构造函数的异常,它必须调用类成员的所有析构函数(因为在调用构造函数代码之前已经构建成功)并释放其内存(可以与析构函数调用一起递归地完成)通过对它们调用适当的删除 ),并释放为该类本身分配的内存。 那么它必须将捕获到的异常从构造函数重新推送给新 ...
  • void **array = new void*[5000]; void **array = new void*[5000];
  • 为什么分配内存是必要的? 因此,您将内存标记为您的内存。 没有其他人可以使用它。 它还验证实际上有可用内存。 如果你的系统只有1000字节的内存,那么选择字节1500来存储一些数据是一个坏主意。 如果我们使用内存而不分配它会发生什么? 没人知道。 您写的地址可能不存在。 可能已经开始使用其他进程,因此您将覆盖其数据。 记忆可以得到保护; 例如,在前一种情况下,操作系统可能会注意到您正在访问另一个进程已声明的内存,并阻止您。 您可能拥有该内存区域,但程序的另一部分由于某种原因正在使用它,并且您已经覆盖了自己的 ...
  • 你应该使用新的,而不是malloc。 当内存不足时抛出新的std :: bad_alloc。 如果分配失败(或者由于其他原因导致初始化有问题),应该从构造函数传播一个异常,因为这是防止析构函数被调用的唯一方法。 如果构造函数成功完成,则必须调用析构函数(当然,除非它是堆分配的并且从不释放)。 You should use new, not malloc. new throws std::bad_alloc when you are out of memory. An exception should be ...
  • 如果它是单个字节,则根本没有理由进行内存分配。 你可以声明一个byte类型的局部变量并传递它。 当需要分配元素数组时,您需要使用malloc() ,并且在编译时您不知道元素的数量。 当您需要分配一个需要在创建它的函数退出后需要在内存中保留的大型结构时,您还需要它。 如果你正在处理一个基本类型的变量,那么你应该简单地声明它是一个局部变量,这意味着它将被自动分配到堆栈上。 If it is a single byte, there is no reason to do memory allocation at ...
  • 不会。自动分配类的实例字段。 如果它们是指针,则为指针分配空间(32位体系结构上4个字节,64位体系结构上8个字节)。 如果希望指针指向对象,则需要指定它们或创建指向它们的对象。 No. Instance fields of your classes are automatically allocated. If they are pointers, space is allocated for your pointers (4 bytes on 32 bit architectures, 8 bytes ...
  • 编译代码编译器时会在原始代码中存储函数起始点的地址。 该地址可以相对于程序的起始位置或绝对存储器地址。 关键是当代码中调用函数(假设范围问题得到处理)时,编译编译器时只需将跳转语句插入到函数代码所在的地址。 为了返回相同的位置,还有一些其他操作正在进行。 所以当你说空间被分配时,它只是函数的字节码所占用的空间加上table inn编译器中的条目,该表示this function is present at this address 对于每种编程语言(编译)而言,这几乎都是C++ 。 至于你的另一部分: si ...

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)