Passa al contenuto
Odoo Menu
  • Accedi
  • Provalo gratis
  • App
    Finanze
    • Contabilità
    • Fatturazione
    • Note spese
    • Fogli di calcolo (BI)
    • Documenti
    • Firma
    Vendite
    • CRM
    • Vendite
    • Punto vendita Negozio
    • Punto vendita Ristorante
    • Abbonamenti
    • Noleggi
    Siti web
    • Configuratore sito web
    • E-commerce
    • Blog
    • Forum
    • Live chat
    • E-learning
    Supply chain
    • Magazzino
    • Produzione
    • PLM
    • Acquisti
    • Manutenzione
    • Qualità
    Risorse umane
    • Dipendenti
    • Assunzioni
    • Ferie
    • Valutazioni
    • Referral dipendenti
    • Parco veicoli
    Marketing
    • Social marketing
    • E-mail marketing
    • SMS marketing
    • Eventi
    • Marketing automation
    • Sondaggi
    Servizi
    • Progetti
    • Fogli ore
    • Assistenza sul campo
    • Helpdesk
    • Pianificazione
    • Appuntamenti
    Produttività
    • Comunicazioni
    • Approvazioni
    • IoT
    • VoIP
    • Knowledge
    • WhatsApp
    App di terze parti Odoo Studio Piattaforma cloud Odoo
  • Settori
    Retail
    • Libreria
    • Negozio di abbigliamento
    • Negozio di arredamento
    • Alimentari
    • Ferramenta
    • Negozio di giocattoli
    Cibo e ospitalità
    • Bar e pub
    • Ristorante
    • Fast food
    • Pensione
    • Grossista di bevande
    • Hotel
    Agenzia immobiliare
    • Agenzia immobiliare
    • Studio di architettura
    • Edilizia
    • Gestione immobiliare
    • Impresa di giardinaggio
    • Associazione di proprietari immobiliari
    Consulenza
    • Società di contabilità
    • Partner Odoo
    • Agenzia di marketing
    • Studio legale
    • Selezione del personale
    • Audit e certificazione
    Produzione
    • Tessile
    • Metallo
    • Arredamenti
    • Alimentare
    • Birrificio
    • Ditta di regalistica aziendale
    Benessere e sport
    • Club sportivo
    • Negozio di ottica
    • Centro fitness
    • Centro benessere
    • Farmacia
    • Parrucchiere
    Commercio
    • Tuttofare
    • Hardware e assistenza IT
    • Ditta di installazione di pannelli solari
    • Calzolaio
    • Servizi di pulizia
    • Servizi di climatizzazione
    Altro
    • Organizzazione non profit
    • Ente per la tutela ambientale
    • Agenzia di cartellonistica pubblicitaria
    • Studio fotografico
    • Punto noleggio di biciclette
    • Rivenditore di software
    Carica tutti i settori
  • Community
    Apprendimento
    • Tutorial
    • Documentazione
    • Certificazioni 
    • Formazione
    • Blog
    • Podcast
    Potenzia la tua formazione
    • Programma educativo
    • Scale Up! Business Game
    • Visita Odoo
    Ottieni il software
    • Scarica
    • Versioni a confronto
    • Note di versione
    Collabora
    • Github
    • Forum
    • Eventi
    • Traduzioni
    • Diventa nostro partner
    • Servizi per partner
    • Registra la tua società di contabilità
    Ottieni servizi
    • Trova un partner
    • Trova un contabile
    • Incontra un esperto
    • Servizi di implementazione
    • Testimonianze dei clienti
    • Supporto
    • Aggiornamenti
    GitHub Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Richiedi una demo
  • Prezzi
  • Aiuto

Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:

  • CRM
  • e-Commerce
  • Contabilità
  • Magazzino
  • PoS
  • Progetti
  • MRP
All apps
È necessario essere registrati per interagire con la community.
Tutti gli articoli Persone Badge
Etichette (Mostra tutto)
odoo accounting v14 pos v15
Sul forum
È necessario essere registrati per interagire con la community.
Tutti gli articoli Persone Badge
Etichette (Mostra tutto)
odoo accounting v14 pos v15
Sul forum
Assistenza

ERROR: insert or update on table "student_marks" violates foreign key constraint "student_marks_subjname_fkey"

Iscriviti

Ricevi una notifica quando c'è un'attività per questo post

La domanda è stata contrassegnata
1 Rispondi
12050 Visualizzazioni
Avatar
Keerthi

ERROR: insert or update on table "student_marks" violates foreign key constraint "student_marks_subjname_fkey"
DETAIL:  Key (subjname)=(38) is not present in table "student_subject".
My Model is:-

# -*- coding: utf-8 -*-

from odoo import models, fields, api, tools, _
from datetime import datetime, date
from odoo.tools import DEFAULT_SERVER_DATE_FORMAT
from odoo.exceptions import ValidationError

#Model of student
class StudentStudent(models.Model):
    _name = 'student.student'
    _order = "admission_no desc"

    name = fields.Char(string = 'Name', required = True)
    student_dob = fields.Date(string = "Date of Birth")
    age = fields.Integer(string = 'Age', compute = 'calcu_age',
        store = True)
    admission_no = fields.Integer('Admission No', required = True)
    place = fields.Char(string = 'Place', required = True)
    photo = fields.Binary(string = 'Image')
    phone_number = fields.Char(string = 'Phone Number', required = True)
    gender = fields.Selection([('male', 'Male'),
                            ('female', 'Female'),
                            ('others', 'Others')],
                            string = 'Gender')
    student_blood_group = fields.Selection([('A+', 'A+ve'),
                                            ('B+', 'B+ve'),
                                            ('O+', 'O+ve'),
                                            ('AB+', 'AB+ve'),
                                             ('A-', 'A-ve'),
                                             ('B-', 'B-ve'),
                                             ('O-', 'O-ve'),
                                             ('AB-', 'AB-ve')],
                                             string = 'Blood Group')
    nationality = fields.Many2one('res.country', string = 'Nationality')
    branchname = fields.Many2one('student.branch', string = 'Branchname')
    active = fields.Boolean(default = True)
    filteration = fields.Selection(selection = 'addfilter')
    sortingfunction = fields.Selection(selection = 'addsort')
    creating = fields.Char(compute = 'action_create')
    browsing = fields.Char(compute = 'action_browse')
    #Existing=fields.Char(compute='action_exists')
   
    #Method to display name and place using name_get method
    @api.multi
    def name_get(self):
        '''Method to display name and place'''
        return [(rec.id, '[' + rec.name + ']' + rec.place) for rec in self]

    # Validation of Phone Number
    @api.constrains('phone_number')
    def _check_phone_number(self):
        if len(self.phone_number) != 10:
            raise ValidationError(_("Invalid Phone Number..."))

    # Create Orm method for creating a record
    @api.multi
    def action_create(self):
        for record in self:
            if record.name == 'lilly':
                record.create({'name': "Joe",
                                'admission_no': 456,
                                'place': "rtr"})

    #Method to calculate age fom Date of Birth
    @api.depends('student_dob')
    def calcu_age(self):
        '''Method to calculate student age'''
        current_dt = datetime.today()
        for rec in self:
            if rec.student_dob:
                start = datetime.strptime(str(rec.student_dob), DEFAULT_SERVER_DATE_FORMAT)
                age_calc = ((current_dt - start).days / 365)
                # Age should be greater than 0
                if age_calc > 0.0:
                    rec.age = age_calc

    #Browse Orm method to browse recordset based on id
    @api.multi
    def action_browse(self):
        for record in self:
            c=self.env['student.student'].browse([2]).name
            print('\n', c)

    @api.multi
    def addfilter(self):
        print("\n\n\n\n")
        a = self.env['student.student'].search([('active', '=', True)])
        k = a.filtered(lambda r:r.age == 21)
        return [(m.name, (m.name).upper()) for m in k]

    @api.multi
    def addsort(self):
        print("\n\n\n\n")
        a = self.env['student.student'].search([('active', '=', True)])
        k = a.sorted(lambda r:r.age)
        return [(m.name, (m.name).upper()) for m in k]
   

    

#Model of Activity
class StudentActivities(models.Model):
    _inherit = 'student.student'
   
    activity_name = fields.Char(string = 'Activity Name',
        required = True)
    activity_score = fields.Integer(string = 'Activity Score',
        required = True)
 #Model of Teacher
class Teacher(models.Model):
    _name = 'student.teacher'
    _rec_name = 'nametr'

    nametr = fields.Char(string = 'Name', required = True)
    age = fields.Integer(string = 'Age')
    photo = fields.Binary(string = 'Image')
    gender = fields.Selection([('male', 'Male'),
                            ('female', 'Female'),
                            ('others', 'Others')],
                            string='Gender')
    nationality = fields.Many2one('res.country', string = 'Nationality')
    state = fields.Selection([
            ('draft', 'Draft'),
            ('in_progress', 'In Progress'),
            ('done', 'Done')],
            default = 'draft')

    @api.one
    def action_confirm(self):
        self.write({'state': 'in_progress'})
   
    @api.one
    def action_finished(self):
        self.write({'state': 'done'})

#Model of Marklist
class StudentMarkList(models.Model):
    _name = 'student.mark'
    _rec_name = 'student_id'

    student_id = fields.Many2one('student.student',
        string = 'StudentName')
    branch = fields.Many2one('student.branch',
        string = 'Branch Name')
    # Setting Related field
    #age = fields.Integer(related='student_id.age',string='Age')
    '''
    total = fields.Integer(string = 'Total Mark', store = True,
        compute = '_compute_total')'''
    subname = fields.One2many('student.marks', 'subjname',
        string = 'Subjectwise Marks')       
    hide_inv_button = fields.Boolean(copy = False, default = True)
    state = fields.Selection([('confirmed', 'Confirm'),
                            ('cancelled', 'Cancel')],
                            string = 'Status', readonly = True,
                            copy = False, index = True,
                            track_visibility = 'onchange')
                                                           
    #Method of Confirm Button
    @api.multi
    def action_confirm(self):
        self.state = 'confirmed'
        self.hide_inv_button = False
                           
#Model of subject
class StudentSubject(models.Model):
    _name = 'student.subject'
   
    name = fields.Char(string = 'Subject Name')   
    branch_id = fields.Many2one("student.branch", string = "Branch",
        index = True,readonly = "1")

#Model of Branch
class StudentBranch(models.Model):
    _name = 'student.branch'
    _rec_name = 'branchname'
   
    branchname = fields.Char(string = 'BranchName')
    branchcode = fields.Integer(string = 'Branch Code')
    subname = fields.One2many('student.subject', 'branch_id',
        string = 'Subject Name')

#Model of Marks
class StudentMarks(models.Model):
    _name = 'student.marks'
    _rec_name = 'subjname'
   
    subjname = fields.Many2one('student.subject', string = 'Subjectname')
    mark = fields.Integer(string = 'Mark')
    branchmark =fields.Many2one('student.branch', string = "Branch",)
                           
    #Dynamic dropdown to display subname based on branch
    @api.onchange('branchmark')
    def _branch_onchange(self):
        res = {}
        res['domain'] = {'subjname':[('branch_id', '=', self.branchmark.id)]}
        return res
   
# onchange handler for subjectwise branch change
@api.onchange('branchname')
def _onchange_branchname(self):
    # set auto-changing field
    self.branch_id = self.branchname
    # Can optionally return a warning and domains
    return {
        'warning': {
            'title': "Something bad happened",
            'message': "It was very bad indeed",
        }
    }

Please Help...

Thanks in Advance

0
Avatar
Abbandona
Avatar
Caret IT Solutions Pvt. Ltd.
Risposta migliore

Hi,

Change this field from 

 subjname = fields.Many2one('student.subject', string = 'Subjectname')

to 

 subjname = fields.Many2one('student.mark', string = 'Subjectname')

0
Avatar
Abbandona
Faris Fathurrahman

thanks a lot, even in my case i got mistake in main model field name, but your answered inspired me to find the problem!

Ti stai godendo la conversazione? Non leggere soltanto, partecipa anche tu!

Crea un account oggi per scoprire funzionalità esclusive ed entrare a far parte della nostra fantastica community!

Registrati
Community
  • Tutorial
  • Documentazione
  • Forum
Open source
  • Scarica
  • Github
  • Runbot
  • Traduzioni
Servizi
  • Hosting Odoo.sh
  • Supporto
  • Aggiornamenti
  • Sviluppi personalizzati
  • Formazione
  • Trova un contabile
  • Trova un partner
  • Diventa nostro partner
Chi siamo
  • La nostra azienda
  • Branding
  • Contattaci
  • Lavora con noi
  • Eventi
  • Podcast
  • Blog
  • Clienti
  • Note legali • Privacy
  • Sicurezza
الْعَرَبيّة Català 简体中文 繁體中文 (台灣) Čeština Dansk Nederlands English Suomi Français Deutsch हिंदी Bahasa Indonesia Italiano 日本語 한국어 (KR) Lietuvių kalba Język polski Português (BR) română русский язык Slovenský jazyk slovenščina Español (América Latina) Español ภาษาไทย Türkçe українська Tiếng Việt

Odoo è un gestionale di applicazioni aziendali open source pensato per coprire tutte le esigenze della tua azienda: CRM, Vendite, E-commerce, Magazzino, Produzione, Fatturazione elettronica, Project Management e molto altro.

Il punto di forza di Odoo è quello di offrire un ecosistema unico di app facili da usare, intuitive e completamente integrate tra loro.

Website made with

Odoo Experience on YouTube

1. Use the live chat to ask your questions.
2. The operator answers within a few minutes.

Live support on Youtube
Watch now