So I have a database that we are using to collect vm statistics. It is always running and writing to a django database. I built my models file to resemble the db. However I have run into quite a few issues. I was wondering if anyone else has run into these issues and found out how to solve them.
First when I try to add a new entry I get an error returned that the value can't be null for the primary key. ORA-01400: cannot insert NULL into ("DEV"."VM_LICENSES"."VM_LICENSE_ID") Isn't django supposed to automatically handle this when you set primary_key = True? Also I want to have a list of available licenses from a table called licenses, and I want to be able to assign them by foreign key to each vm by its foreign key in an intermediary table called vm_licenses. Here are the model snippets for that process. However, I can't get manytomany to work right. Bascially our system admins need to be able to manage the associated licenses for each vm. I'm trying to allow them to do this with the admin page. People keep pointing me to the documentation for manytomany but obviously I can't seem to figure out how django uses already established databases. The django documentation doesn't really explain how things work. Thus, anything outside the basic blog app is unknown territory you just kinda have to plug away in the dark. I'm tired of plugging away trying to figure out how this framework works. I would greatly appreciate it if someone could help me understand how the django framework interacts with already established databases and how to do what I want. class License(models.Model): license_id = models.BigIntegerField(primary_key = True, editable = False, db_column='license_id') license_authority_id = models.ForeignKey(License_authoritie, on_delete = models.PROTECT, db_column='license_authority_id') product = models.CharField(max_length = 20) class Meta: managed = False db_table = 'licenses' ordering = ['product'] def __unicode__(self): # Python 3: def __str__(self): return self.product class Vm_license(models.Model): vm_license_id = models.AutoField(primary_key = True, db_column='vm_license_id') license_id = models.ForeignKey(License, on_delete = models.PROTECT, db_column='license_id') vm_id = models.ForeignKey(Vm, on_delete = models.PROTECT, db_column='vm_id') class Meta: managed = False db_table = 'vm_licenses' Here is my entire models file let me know if you see any problems with it because I don't know why i cant add entries. from __future__ import unicode_literals from django.db import models from django.core.exceptions import ValidationError from django.contrib.auth.models import User class Cidr_allocation(models.Model): cidr_allocation_id = models.BigIntegerField(primary_key = True, editable = False, db_column = 'cidr_allocation_id') cidr = models.CharField(max_length = 40) allocation_name = models.CharField(max_length = 30) allocation_date = models.DateTimeField(auto_now = False, auto_now_add = True) deallocation_date = models.DateTimeField(auto_now=False, auto_now_add=False) allocation_source = models.CharField(max_length = 30) public_address = models.CharField(max_length = 1) class Meta: managed = False db_table = 'cidr_allocations' def clean(self): if self.public_address != 'Y' and self.public_address != 'N': raise ValidationError('Please enter a Y or N') def __unicode__(self): # Python 3: def __str__(self): return self.allocation_name class Customer(models.Model): customer_id = models.BigIntegerField(primary_key = True, editable = False, db_column = 'customer_id') customer_name = models.CharField(max_length = 30) inactive = models.CharField(max_length = 1) class Meta: managed = False db_table = 'customers' ordering = ['customer_name'] def __unicode__(self): # Python 3: def __str__(self): return self.customer_name def clean(self): if self.inactive != 'Y' and self.inactive != 'N': raise ValidationError('Please enter a Y or N') class Vcenter(models.Model): vcenter_id = models.BigIntegerField(primary_key = True, editable = False, db_column = 'vcenter_id') vcenter_ip_address = models.BinaryField() vcenter_uuid = models.CharField(max_length = 50) username = models.CharField(max_length = 20) password = models.CharField(max_length = 20) name = models.CharField(max_length = 30) class Meta: managed = False db_table = 'vcenters' def __unicode__(self): # Python 3: def __str__(self): return self.name class Datacenter(models.Model): datacenter_id = models.BigIntegerField(primary_key = True, editable = False, db_column = 'datacenter_id') vcenter_id = models.ForeignKey(Vcenter, on_delete = models.PROTECT, db_column='vcenter_id') datacenter_mor = models.CharField(max_length = 20) datacenter_name = models.CharField(max_length = 30) class Meta: managed = False db_table = 'datacenters' def __unicode__(self): # Python 3: def __str__(self): return self.datacenter_name class Storage_tier(models.Model): storage_tier_id = models.BigIntegerField(primary_key = True, editable = False, db_column = 'storage_tier_id') tier_name = models.CharField(max_length = 20) reserved_iops = models.BigIntegerField() price_per_gb = models.DecimalField(max_digits = 7, decimal_places = 4) class Meta: managed = False db_table = 'storage_tiers' ordering = ['tier_name'] def __unicode__(self): # Python 3: def __str__(self): return self.tier_name class Datastore(models.Model): datastore_id = models.BigIntegerField(primary_key = True, editable = False, db_column = 'datastore_id') datastore_mor = models.CharField(max_length = 20) storage_tier_id = models.ForeignKey(Storage_tier, on_delete = models.PROTECT, db_column='storage_tier_id') datastore_name = models.CharField(max_length = 30) datacenter_id = models.ForeignKey(Datacenter, on_delete = models.PROTECT, db_column='datacenter_id') type = models.CharField(max_length = 10) class Meta: managed = False db_table = 'datastores' def __unicode__(self): # Python 3: def __str__(self): return self.datastore_name class Esxi_license(models.Model): esxi_license_id = models.BigIntegerField(primary_key = True, editable = False, db_column = 'esxi_license_id') license_type = models.CharField(max_length = 40) class Meta: managed = False db_table = 'esxi_licenses' def __unicode__(self): # Python 3: def __str__(self): return self.license_type class Guest_o(models.Model): guest_os_id = models.BigIntegerField(primary_key = True, editable = False, db_column = 'guest_os_id') guest_os = models.CharField(max_length = 60) class Meta: managed = False db_table = 'guest_os' def __unicode__(self): # Python 3: def __str__(self): return self.guest_os class Host(models.Model): host_id = models.BigIntegerField(primary_key = True, editable = False, db_column = 'host_id') host_mor = models.CharField(max_length = 20) esxi_license_id = models.ForeignKey(Esxi_license, on_delete = models.PROTECT, db_column='esxi_license_id') datacenter_id = models.ForeignKey(Datacenter, on_delete = models.PROTECT, db_column='datacenter_id') host_ip_address = models.BinaryField() mfgr = models.CharField(max_length = 40) model = models.CharField(max_length = 40) cores = models.BigIntegerField() core_ghz = models.DecimalField(max_digits = 8, decimal_places = 5) processor_type = models.CharField(max_length = 60) memory_gb = models.DecimalField(max_digits = 9, decimal_places = 5) class Meta: managed = False db_table = 'hosts' def __str__(self): ip = self.host_ip_address.decode("utf-16") ip = ip.decode("utf-8") return ip class Ip_addresse(models.Model): ip_address_id = models.BigIntegerField(primary_key = True, editable = False, db_column = 'ip_address_id') ip_address = models.BinaryField() cidr_allocation_id = models.ForeignKey(Cidr_allocation, db_column='cidr_allocation_id') class Meta: managed = False db_table = 'ip_addresses' class Ip_address_usage_historie(models.Model): datetime = models.DateTimeField(auto_now = False, auto_now_add = False) bytes_sent = models.BigIntegerField() bytes_received = models.BigIntegerField() ip_address_id = models.ForeignKey(Ip_addresse, on_delete = models.PROTECT, db_column='ip_address_id') load_sequence = models.BigIntegerField() class Meta: managed = False db_table = 'ip_address_usage_histories' class License_authoritie(models.Model): license_authority_id = models.BigIntegerField(primary_key = True, editable = False, db_column = 'license_authority_id') licensing_authority = models.CharField(max_length = 30) class Meta: managed = False db_table = 'license_authorities' def __unicode__(self): # Python 3: def __str__(self): return self.licensing_authority class Nas_device(models.Model): nas_device_id = models.BigIntegerField(primary_key = True, editable = False, db_column = 'nas_device_id') device_name = models.CharField(max_length = 20) ip_address = models.BinaryField() storage_tier_id = models.ForeignKey(Storage_tier, on_delete = models.PROTECT, db_column='storage_tier_id') class Meta: managed = False db_table = 'nas_devices' ordering = ['device_name'] def __unicode__(self): # Python 3: def __str__(self): return self.device_name class Nas_usage(models.Model): vm_nas_usage_history_id = models.BigIntegerField(primary_key = True, editable = False, db_column = 'vm_nas_usage_history_id') datetime = models.DateTimeField(auto_now = False, auto_now_add = False) provisioned_gb = models.DecimalField(max_digits = 13, decimal_places = 5) consumed_gb = models.DecimalField(max_digits = 13, decimal_places = 5) nas_device_id = models.ForeignKey(Nas_device, on_delete = models.PROTECT, db_column='nas_device_id') customer_id = models.ForeignKey(Customer, on_delete = models.PROTECT, db_column='customer_id') class Meta: managed = False db_table = 'nas_usage' class Network_device(models.Model): network_device_id = models.BigIntegerField(primary_key = True, editable = False, db_column = 'network_device_id') name = models.CharField(max_length = 20) management_ip_address = models.BinaryField() snmp_version = models.DecimalField(max_digits = 1, decimal_places = 0) snmp_username = models.CharField(max_length = 20) snmp_security = models.CharField(max_length = 12) snmp_password = models.CharField(max_length = 20) arp_cache_oid = models.CharField(max_length = 40) snmp_priv_passphrase = models.CharField(max_length = 20) snmp_auth_protocol = models.CharField(max_length = 3) snmp_priv_protocol = models.CharField(max_length = 3) class Meta: managed = False db_table = 'network_devices' ordering = ['name'] def __unicode__(self): # Python 3: def __str__(self): return self.name def clean(self): snmp_security = set(['AuthPriv', 'NoAuthNoPriv', 'AuthNoPriv']) auth_protocols = set(['MD5', 'SHA']) priv_protocols = set(['AES', 'DES']) if self.snmp_version < 1 or self.snmp_version > 3: raise ValidationError('Please enter a 1, 2 or 3') if self.snmp_security not in snmp_security: raise ValidationError('Please enter AuthPriv, NoAuthNoPriv or AuthNoPriv') if self.snmp_auth_protocol not in auth_protocols: raise ValidationError('Please enter MD5 or SHA') if self.snmp_priv_protocol not in priv_protocols: raise ValidationError('Please enter AES or DES') class Network_device_ip_addresse(models.Model): network_device = models.ForeignKey(Network_device, on_delete = models.PROTECT) ip_address_id = models.ForeignKey(Ip_addresse, on_delete = models.PROTECT, db_column='ip_address_id') class Meta: managed = False db_table = 'network_device_ip_addresses' class Network_device_mac_addresse(models.Model): network_device = models.ForeignKey(Network_device, on_delete = models.PROTECT) mac_address = models.CharField(max_length = 17) datacenter_id = models.ForeignKey(Datacenter, on_delete = models.PROTECT, db_column='datacenter_id') class Meta: managed = False db_table = 'network_device_mac_addresses' ordering = ['mac_address'] def __unicode__(self): # Python 3: def __str__(self): return self.mac_address class Resource_pool(models.Model): resource_pool_id = models.BigIntegerField(primary_key = True, editable = False, db_column = 'resource_pool') resource_pool_mor = models.CharField(max_length = 20) resource_pool_name = models.CharField(max_length = 30) cpu_ghz_reservation = models.DecimalField(max_digits = 8, decimal_places = 5) cpu_ghz_limit = models.DecimalField(max_digits = 8, decimal_places = 5) cpu_reservation_expandable = models.CharField(max_length = 1) ram_gb_reservation = models.DecimalField(max_digits = 9, decimal_places = 5) ram_gb_limit = models.DecimalField(max_digits = 9, decimal_places = 5) ram_reservation_expandable = models.CharField(max_length = 1) cpu_unlimited = models.CharField(max_length = 1) ram_unlimited = models.CharField(max_length = 1) datacenter_id = models.ForeignKey(Datacenter, on_delete = models.PROTECT, db_column='datacenter_id') class Meta: managed = False db_table = 'resource_pools' class Vm_group(models.Model): vm_group_id = models.BigIntegerField(primary_key = True, editable = False, db_column = 'vm_group_id') customer_id = models.ForeignKey(Customer, on_delete = models.PROTECT, db_column='customer_id') vm_group_name = models.CharField(max_length = 30) class Meta: managed = False db_table = 'vm_groups' ordering = ['vm_group_name'] def __unicode__(self): # Python 3: def __str__(self): return self.vm_group_name class Vm(models.Model): vm_id = models.BigIntegerField(primary_key = True, editable = False, db_column='vm_id') vm_mor = models.CharField(max_length = 20) vm_name = models.CharField(max_length = 256) vm_group_id = models.ForeignKey(Vm_group, on_delete = models.PROTECT, db_column ='vm_group_id') vm_display_name = models.CharField(max_length = 30) datacenter_id = models.ForeignKey(Datacenter, on_delete = models.PROTECT, db_column='datacenter_id') vcd_managed = models.CharField(max_length = 60) class Meta: managed = False db_table = 'vms' def __unicode__(self): # Python 3: def __str__(self): return self.vm_name class Vm_compute_historie(models.Model): vm_compute_history_id = models.BigIntegerField(primary_key = True, editable = False, db_column = 'vm_compute_history') vm_id = models.ForeignKey(Vm, on_delete = models.PROTECT, db_column='vm_id') power_state = models.DecimalField(max_digits = 1, decimal_places = 0) cpu_core_allocation = models.DecimalField(max_digits = 8, decimal_places = 5) cpu_ghz_reservation = models.DecimalField(max_digits = 8, decimal_places = 5) cpu_ghz_limit = models.DecimalField(max_digits = 8, decimal_places = 5) ram_gb_allocation = models.DecimalField(max_digits = 9, decimal_places = 5) ram_gb_reservation = models.DecimalField(max_digits = 9, decimal_places = 5) ram_gb_limit = models.DecimalField(max_digits = 9, decimal_places = 5) datetime = models.DateTimeField(auto_now = False, auto_now_add = False) host_id = models.ForeignKey(Host, on_delete = models.PROTECT, db_column='host_id') esxi_license_id = models.ForeignKey(Esxi_license, on_delete = models.PROTECT, db_column='esxi_license_id') resource_pool_id= models.ForeignKey(Resource_pool, on_delete = models.PROTECT, db_column='resource_pool_id') fault_tolerance = models.CharField(max_length = 1) guest_os_id= models.ForeignKey(Guest_o, on_delete = models.PROTECT, db_column='guest_os_id') class Meta: managed = False db_table = 'vm_compute_histories' class Vm_compute_usage_historie(models.Model): vm_id = models.ForeignKey(Vm, on_delete = models.PROTECT, db_column='vm_id') datetime = models.DateTimeField(auto_now = False, auto_now_add = False) cpu_ghz_hours = models.DecimalField(max_digits = 13, decimal_places = 5) ram_gb_hours = models.DecimalField(max_digits = 13, decimal_places = 5) class Meta: managed = False db_table = 'vm_compute_usage_histories' class Vm_ip_address_historie(models.Model): vm_ip_address_history_id = models.BigIntegerField(primary_key = True, editable = False, db_column = 'vm_ip_address_history_id') vm_id = models.ForeignKey(Vm, on_delete = models.PROTECT, db_column='vm_id') ip_address= models.ForeignKey(Ip_addresse, on_delete = models.PROTECT) allocation_date = models.DateTimeField(auto_now = False, auto_now_add = True) deallocation_date = models.DateTimeField(auto_now = False, auto_now_add = False) class Meta: managed = False db_table = 'vm_ip_address_histories' class Vm_mac_addresse(models.Model): vm_mac_address_id = models.BigIntegerField(primary_key = True, editable = False, db_column = 'vm_mac_address_id') vm_id = models.ForeignKey(Vm, on_delete = models.PROTECT, db_column='vm_id') mac_address = models.CharField(max_length = 20) datetime = models.DateTimeField(auto_now = False, auto_now_add = False) datacenter_id = models.ForeignKey(Datacenter, on_delete = models.PROTECT, db_column='datacenter_id') class Meta: managed = False db_table = 'vm_mac_addresses' class Vm_nas_usage_historie(models.Model): vm_nas_usage_history_id = models.BigIntegerField(primary_key = True, editable = False, db_column = 'vm_nas_usage_history_id') datetime = models.DateTimeField(auto_now = False, auto_now_add = False) provisioned_gb = models.DecimalField(max_digits = 13, decimal_places = 5) consumed_gb = models.DecimalField(max_digits = 13, decimal_places = 5) nas_device_id = models.ForeignKey(Nas_device, on_delete = models.PROTECT, db_column='nas_device_id') customer_id = models.ForeignKey(Customer, on_delete = models.PROTECT, db_column='customer_id') class Meta: managed = False db_table = 'vm_nas_usage_histories' class Vm_storage_historie(models.Model): vm_storage_history_id = models.BigIntegerField(primary_key = True, editable = False, db_column = 'vm_storage_history_id') vm_id = models.ForeignKey(Vm, on_delete = models.PROTECT, db_column='vm_id') datastore_id= models.ForeignKey(Datastore, on_delete = models.PROTECT, db_column = 'datastore_id') datetime = models.DateTimeField(auto_now = False, auto_now_add = False) provisioned_gb = models.DecimalField(max_digits = 13, decimal_places = 5) consumed_gb = models.DecimalField(max_digits = 13, decimal_places = 5) class Meta: managed = False db_table = 'vm_storage_histories' class Vm_storage_perf_historie(models.Model): vm_storage_perf_history_id = models.BigIntegerField(primary_key = True, editable = False, db_column = 'vm_storage_perf_history_id') datastore_id = models.ForeignKey(Datastore, on_delete = models.PROTECT, db_column = 'datastore_id') vm_id = models.ForeignKey(Vm, on_delete = models.PROTECT, db_column='vm_id') datetime = models.DateTimeField(auto_now = False, auto_now_add = False) average_reads_per_sec = models.BigIntegerField() average_writes_per_sec = models.BigIntegerField() max_read_requests = models.BigIntegerField() max_write_requests = models.BigIntegerField() sum_read_requests = models.BigIntegerField() sum_write_requests = models.BigIntegerField() class Meta: managed = False db_table = 'vm_storage_perf_histories' class License(models.Model): license_id = models.BigIntegerField(primary_key = True, editable = False, db_column='license_id') license_authority_id = models.ForeignKey(License_authoritie, on_delete = models.PROTECT, db_column='license_authority_id') product = models.CharField(max_length = 20) class Meta: managed = False db_table = 'licenses' ordering = ['product'] def __unicode__(self): # Python 3: def __str__(self): return self.product class Vm_license(models.Model): vm_license_id = models.AutoField(primary_key = True, db_column='vm_license_id') license_id = models.ForeignKey(License, on_delete = models.PROTECT, db_column='license_id') vm_id = models.ForeignKey(Vm, on_delete = models.PROTECT, db_column='vm_id') class Meta: managed = False db_table = 'vm_licenses' class Vm_license_historie(models.Model): vm_license_history_id = models.BigIntegerField(primary_key = True, editable = False, db_column = 'vm_license_history_id') license_id = models.ForeignKey(License, on_delete = models.PROTECT, db_column='license_id') vm_id = models.ForeignKey(Vm, on_delete = models.PROTECT, db_column='vm_id') assignment_date = models.DateTimeField(auto_now = False, auto_now_add = False) deassignment_date = models.DateTimeField(auto_now = False, auto_now_add = False) class Meta: managed = False db_table = 'vm_license_histories' class Vm_backup_storage(models.Model): vm_backup_storage_id = models.BigIntegerField(primary_key = True, editable = False, db_column = 'vm_backup_storage_id') customer_id = models.ForeignKey(Customer, on_delete = models.PROTECT, db_column='customer_id') datetime = models.DateTimeField(auto_now = False, auto_now_add = False) consumed_gb = models.CharField(max_length = 200) class Meta: managed = False db_table = 'vm_backup_storage' class UserProfile(models.Model): user = models.OneToOneField(User) website = models.URLField(blank=True) picture = models.ImageField(upload_to='profile_images', blank=True) def __unicode__(self): return self.user.username -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at http://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/224a3944-9386-490e-bcc0-842d9f1ebd52%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.