skip to Main Content

this is part of the database. The extention is .sql

-- phpMyAdmin SQL Dump
-- version 3.2.0.1
-- http://www.phpmyadmin.net
--
-- Host: localhost
-- Generation Time: May 20, 2011 at 05:08 PM
-- Server version: 5.1.36
-- PHP Version: 5.2.9-2

SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";


/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8 */;

--
-- Database: `bincomphptest`
--

-- --------------------------------------------------------

--
-- Table structure for table `agentname`
--

DROP TABLE IF EXISTS `agentname`;
CREATE TABLE IF NOT EXISTS `agentname` (
  `name_id` int(11) NOT NULL AUTO_INCREMENT,
  `firstname` varchar(255) NOT NULL,
  `lastname` varchar(255) NOT NULL,
  `email` varchar(255) DEFAULT NULL,
  `phone` char(13) NOT NULL,
  `pollingunit_uniqueid` int(11) NOT NULL,
  PRIMARY KEY (`name_id`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=5 ;

I was creating a new database on django with mysqlite but I think I’m inexperience and this maybe possible

2

Answers


  1. To interpret these values in django you must look carefully at each field type so that you can create the variables that will store these values, such as name_id, firstname, lastname

    # settings.py 
    DATABASES = {
        'default': {
            'ENGINE': 'django.db.backends.mysql',
            'NAME': 'django',
            'USER' : 'userid',
            'PASSWORD' :'password',
            'HOST' : 'localhost'
        }
    }
    

    this example should work once the table has been defined in models and that you have added the respective app 'exampleApp.apps...' in settings.py.

    import uuid
    from django.db import models
    
    class Agent(models.Model): 
        name_id = models.UUIDField(primary_key=True, editable=False)
        firstname = models.CharField(max_length=255)
        lastname = models.CharField(max_length=255)
        email  = models.EmailField(max_length=255)
        phone  = models.CharField(max_length=25)
    
    Login or Signup to reply.
  2. Django can read legacy databases and even auto-generate the models for them,

    connect to the db from settings and then run this command from your terminal

    python manage.py inspectdb
    

    it will print the models and you can use it as normal Django models

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search