問題描述
我正在嘗試使用一個管理模塊在數據庫中創(chuàng)建一個新表.我的設置
I am trying to have an admin module I am working on create a new table in the database. What I have setup in
app/code/local/Foo/BAR/sql/mysql4-install-0.1.0.php
app/code/local/Foo/BAR/sql/mysql4-install-0.1.0.php
<?php
$installer = $this;
$installer->startSetup();
$installer->run("
DROP TABLE IF EXISTS {$this->getTable('notes')};
CREATE TABLE {$this->getTable('notes')} (
`ppr_id` int(11) NOT NULL AUTO_INCREMENT,
`notesku` bigint(20) NOT NULL,
`notestatus` smallint(16),
PRIMARY KEY (`notes`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8
");
$installer->endSetup();
這個在 app/code/local/Foo/BAR/etc/config.xml
and this in app/code/local/Foo/BAR/etc/config.xml
<?xml version="1.0"?>
<config>
<modules>
<Foo_BAR>
<version>0.1.0</version>
</Foo_BAR>
</modules>
<global>
<models>
<BAR>
<class>Foo_BAR_Model</class>
<resourceModel>BAR_mysql4</resourceModel>
</BAR>
<BAR_myslq4>
<class>Foo_BAR_Model_Mysql4</class>
<entities>
<BAR>
<table>notes</table>
</BAR>
</entities>
</BAR_myslq4>
</models>
<resources>
<BAR_setup>
<setup>
<module>Foo_BAR</module>
</setup>
<connection>
<use>core_setup</use>
</connection>
</BAR_setup>
<BAR_write>
<connection>
<use>core_write</use>
</connection>
</BAR_write>
<BAR_read>
<connection>
<use>core_read</use>
</connection>
</BAR_read>
</resources>
</global>
<admin>
<routers>
<BAR>
<use>admin</use>
<args>
<module>Foo_BAR</module>
<frontName>bar</frontName>
</args>
</BAR>
</routers>
</admin>
<adminhtml>
<menu>
<catalog>
<children>
<BAR_menu translate="title" module="BAR">
<title>BAR</title>
<children>
<list translate="title" module="BAR">
<title>Bar</title>
<action>bar/index/index</action>
</list>
</children>
</BAR_menu>
</children>
</catalog>
</menu>
</adminhtml>
</config>
我使用的案例與我的公司大寫且模塊名稱全部大寫的示例相匹配.我在想也許這讓我絆倒了?我的理解是,一旦我運行點擊該模塊的頁面,它將觸發(fā)該 mysql 以創(chuàng)建表.那是對的嗎?還有什么我應該做的嗎?
The case I am using matches this example where my company is capitalized and the module name is all uppercase. I am thinking maybe that is tripping me up? My understanding is that once I run the page that hits that module it will trigger that mysql to create the table. Is that correct? Is there something else I should be doing?
我非常感謝您對此的任何幫助.
I greatly appreciate any help with this.
推薦答案
如果安裝/升級腳本未運行,請檢查以下事項:
If a setup/upgrade script isn't running, here are some things to check:
Magento 是否正在加載您的模塊?轉到系統 > 配置 > 高級 > 高級,然后查看您的模塊是否出現在禁用模塊輸出"列表中.如果沒有,則 Magento 根本不會加載您的模塊,因此不會運行任何安裝腳本.正如 Cags 在他的評論中指出的那樣,如果您尚未創(chuàng)建模塊,您將需要
app/etc/modules
中的一個 xml 文件來告訴 Magento 加載您的模塊.
Is Magento loading your module? Go to System > Configuration > Advanced > Advanced and see if your module appears in the "Disable Module Output" list. If it doesn't, Magento isn't loading your module at all, and therefore won't run any setup scripts. As Cags noted in his comment, you'll need an xml file in
app/etc/modules
to tell Magento to load your module if you haven't already created one.
確保您的資源在 config.xml 文件中的正確位置聲明.它們應該在 <global>
標簽內(這在您的情況下似乎是正確的).
Make sure your resources are declared in the correct place in the config.xml file. They should be inside the <global>
tag (this appears to be correct in your case).
確保您的安裝文件位于正確的位置.它們應該位于模塊內的 sql/文件夾中.我認為這是你的問題,這個例子中的安裝文件應該是 app/code/local/Foo/BAR/sql/BAR_setup/mysql4-install-0.1.0.php
Make sure your setup files are in the correct location. They should be in a sql/ folder inside your module. I think this is your problem, the setup file in this example should be app/code/local/Foo/BAR/sql/BAR_setup/mysql4-install-0.1.0.php
檢查完以上所有內容后,如果您有一個用于調試的 IDE(并且如果您正在做任何嚴肅的 Magento 工作,請幫自己一個忙并獲得一個),在設置中設置一個斷點文件并確保它被命中.
Having checked all of the above, if you have an IDE set up for debugging (and if you're doing any serious Magento work, do yourself a favor and get one up), set a breakpoint in the setup file and make sure it's being hit.
檢查數據庫中的 core_resource
表中的 BAR_setup
條目.如果它在那里,Magento 已經運行了一次安裝腳本并且不會再次運行它.如果您需要再次運行安裝腳本,請刪除此記錄.同樣,如果您需要重新運行升級腳本,您可以更改版本號(但請確保您了解第二次運行安裝/升級腳本的后果).
Check the core_resource
table in the database for a BAR_setup
entry. If it's there, Magento has run the setup script once and won't run it again. If you need to run your setup script again, delete this record. Likewise you can change the version numbers if you ever need to re-run upgrade scripts (but make sure you understand the consequences of running setup/upgrade scripts a second time if you do).
如果所有其他方法都失敗,請查看 Alan Storm 的 Magento 安裝腳本調試指南.
If all else fails check out Alan Storm's guide to debugging Magento setup scripts.
這篇關于從 magento 模塊創(chuàng)建一個新表的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!