Welcome Guest, Not a member yet? Register   Sign In
Dbforge failes: Field information is required
#1

[eluser]murphy2006[/eluser]
Hello,

I am trying to create a table using the dbforge.
I am using the below code but that only renders in the error: Field information is required.

Code:
$this->load->dbforge();
            
        if ($this->db->table_exists('fe_test'))
    
        { echo "Table already exists"; } else {
        
        $this->dbforge->create_table('fe_test');
    
        }

Does anyone know what the problem is? I can run all sorts of DB queries so I guess
the database driver is already running (or is there anything I need to setup).

Thanks!
#2

[eluser]Seppo[/eluser]
The problem is that the table has not fields. You should add them before create the table.
For example
Code:
$fields = array(
                        'blog_id' => array(
                                                 'type' => 'INT',
                                                 'constraint' => 5,
                                                 'unsigned' => TRUE,
                                                 'auto_increment' => TRUE
                                          ),
                        'blog_title' => array(
                                                 'type' => 'VARCHAR',
                                                 'constraint' => '100',
                                          ),
                        'blog_author' => array(
                                                 'type' =>'VARCHAR',
                                                 'constraint' => '100',
                                                 'default' => 'King of Town',
                                          ),
                        'blog_description' => array(
                                                 'type' => 'TEXT',
                                                 'null' => TRUE,
                                          ),
                );

$this->dbforge->add_field($fields);

$this->dbforge->add_key('blog_id', TRUE);
// gives PRIMARY KEY (blog_id)

$this->dbforge->add_key('blog_title');
// gives KEY (blog_title)

$this->dbforge->create_table('blog');

More info: http://ellislab.com/codeigniter/user-gui...eate_table
#3

[eluser]murphy2006[/eluser]
Wow, thanks for the quick reply!
Your solution worked perfectly fine!

Have a nice day!




Theme © iAndrew 2016 - Forum software by © MyBB