为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
最满意答案
你应该使用新的,而不是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];
-
为什么分配内存?(Why allocate memory? (C++))[2022-01-22]
为什么分配内存是必要的? 因此,您将内存标记为您的内存。 没有其他人可以使用它。 它还验证实际上有可用内存。 如果你的系统只有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 ...
-
何时在C中分配内存?(When to allocate memory in C?)[2022-08-29]
如果它是单个字节,则根本没有理由进行内存分配。 你可以声明一个byte类型的局部变量并传递它。 当需要分配元素数组时,您需要使用malloc() ,并且在编译时您不知道元素的数量。 当您需要分配一个需要在创建它的函数退出后需要在内存中保留的大型结构时,您还需要它。 如果你正在处理一个基本类型的变量,那么你应该简单地声明它是一个局部变量,这意味着它将被自动分配到堆栈上。 If it is a single byte, there is no reason to do memory allocation at ... -
在C ++构造函数中,我是否必须为实例字段分配空间?(In a C++ constructor do I have to allocate space for my instance fields?)[2024-01-24]
不会。自动分配类的实例字段。 如果它们是指针,则为指针分配空间(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 ... -
c ++如何分配类方法(How does c++ allocate class methods)[2023-11-26]
编译代码编译器时会在原始代码中存储函数起始点的地址。 该地址可以相对于程序的起始位置或绝对存储器地址。 关键是当代码中调用函数(假设范围问题得到处理)时,编译编译器时只需将跳转语句插入到函数代码所在的地址。 为了返回相同的位置,还有一些其他操作正在进行。 所以当你说空间被分配时,它只是函数的字节码所占用的空间加上table inn编译器中的条目,该表示this function is present at this address 对于每种编程语言(编译)而言,这几乎都是C++ 。 至于你的另一部分: si ...